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