]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/SerialPortLib.h
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Include / Library / SerialPortLib.h
1 /** @file
2 This library class provides common serial I/O port functions.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2012 - 2014, ARM Ltd. All rights reserved.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef __SERIAL_PORT_LIB__
11 #define __SERIAL_PORT_LIB__
12
13 #include <Uefi/UefiBaseType.h>
14 #include <Protocol/SerialIo.h>
15
16 /**
17 Initialize the serial device hardware.
18
19 If no initialization is required, then return RETURN_SUCCESS.
20 If the serial device was successfully initialized, then return RETURN_SUCCESS.
21 If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
22
23 @retval RETURN_SUCCESS The serial device was initialized.
24 @retval RETURN_DEVICE_ERROR The serial device could not be initialized.
25
26 **/
27 RETURN_STATUS
28 EFIAPI
29 SerialPortInitialize (
30 VOID
31 );
32
33 /**
34 Write data from buffer to serial device.
35
36 Writes NumberOfBytes data bytes from Buffer to the serial device.
37 The number of bytes actually written to the serial device is returned.
38 If the return value is less than NumberOfBytes, then the write operation failed.
39 If Buffer is NULL, then ASSERT().
40 If NumberOfBytes is zero, then return 0.
41
42 @param Buffer Pointer to the data buffer to be written.
43 @param NumberOfBytes Number of bytes to written to the serial device.
44
45 @retval 0 NumberOfBytes is 0.
46 @retval >0 The number of bytes written to the serial device.
47 If this value is less than NumberOfBytes, then the write operation failed.
48
49 **/
50 UINTN
51 EFIAPI
52 SerialPortWrite (
53 IN UINT8 *Buffer,
54 IN UINTN NumberOfBytes
55 );
56
57
58 /**
59 Read data from serial device and save the datas in buffer.
60
61 Reads NumberOfBytes data bytes from a serial device into the buffer
62 specified by Buffer. The number of bytes actually read is returned.
63 If the return value is less than NumberOfBytes, then the rest operation failed.
64 If Buffer is NULL, then ASSERT().
65 If NumberOfBytes is zero, then return 0.
66
67 @param Buffer Pointer to the data buffer to store the data read from the serial device.
68 @param NumberOfBytes Number of bytes which will be read.
69
70 @retval 0 Read data failed, no data is to be read.
71 @retval >0 Actual number of bytes read from serial device.
72
73 **/
74 UINTN
75 EFIAPI
76 SerialPortRead (
77 OUT UINT8 *Buffer,
78 IN UINTN NumberOfBytes
79 );
80
81 /**
82 Polls a serial device to see if there is any data waiting to be read.
83
84 Polls a serial device to see if there is any data waiting to be read.
85 If there is data waiting to be read from the serial device, then TRUE is returned.
86 If there is no data waiting to be read from the serial device, then FALSE is returned.
87
88 @retval TRUE Data is waiting to be read from the serial device.
89 @retval FALSE There is no data waiting to be read from the serial device.
90
91 **/
92 BOOLEAN
93 EFIAPI
94 SerialPortPoll (
95 VOID
96 );
97
98 /**
99 Sets the control bits on a serial device.
100
101 @param Control Sets the bits of Control that are settable.
102
103 @retval RETURN_SUCCESS The new control bits were set on the serial device.
104 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
105 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
106
107 **/
108 RETURN_STATUS
109 EFIAPI
110 SerialPortSetControl (
111 IN UINT32 Control
112 );
113
114 /**
115 Retrieve the status of the control bits on a serial device.
116
117 @param Control A pointer to return the current control signals from the serial device.
118
119 @retval RETURN_SUCCESS The control bits were read from the serial device.
120 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
121 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
122
123 **/
124 RETURN_STATUS
125 EFIAPI
126 SerialPortGetControl (
127 OUT UINT32 *Control
128 );
129
130 /**
131 Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,
132 data bits, and stop bits on a serial device.
133
134 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the
135 device's default interface speed.
136 On output, the value actually set.
137 @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the
138 serial interface. A ReceiveFifoDepth value of 0 will use
139 the device's default FIFO depth.
140 On output, the value actually set.
141 @param Timeout The requested time out for a single character in microseconds.
142 This timeout applies to both the transmit and receive side of the
143 interface. A Timeout value of 0 will use the device's default time
144 out value.
145 On output, the value actually set.
146 @param Parity The type of parity to use on this serial device. A Parity value of
147 DefaultParity will use the device's default parity value.
148 On output, the value actually set.
149 @param DataBits The number of data bits to use on the serial device. A DataBits
150 vaule of 0 will use the device's default data bit setting.
151 On output, the value actually set.
152 @param StopBits The number of stop bits to use on this serial device. A StopBits
153 value of DefaultStopBits will use the device's default number of
154 stop bits.
155 On output, the value actually set.
156
157 @retval RETURN_SUCCESS The new attributes were set on the serial device.
158 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
159 @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.
160 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
161
162 **/
163 RETURN_STATUS
164 EFIAPI
165 SerialPortSetAttributes (
166 IN OUT UINT64 *BaudRate,
167 IN OUT UINT32 *ReceiveFifoDepth,
168 IN OUT UINT32 *Timeout,
169 IN OUT EFI_PARITY_TYPE *Parity,
170 IN OUT UINT8 *DataBits,
171 IN OUT EFI_STOP_BITS_TYPE *StopBits
172 );
173
174 #endif