]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/SerialPortLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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
2f88bd3a
MK
53 IN UINT8 *Buffer,\r
54 IN UINTN NumberOfBytes\r
ef4ce186 55 );\r
fd7a76af 56\r
fd7a76af 57/**\r
58 Read data from serial device and save the datas in buffer.\r
9095d37b 59\r
d69107aa 60 Reads NumberOfBytes data bytes from a serial device into the buffer\r
9095d37b 61 specified by Buffer. The number of bytes actually read is returned.\r
d69107aa 62 If the return value is less than NumberOfBytes, then the rest operation failed.\r
9095d37b 63 If Buffer is NULL, then ASSERT().\r
d69107aa 64 If NumberOfBytes is zero, then return 0.\r
fd7a76af 65\r
d69107aa 66 @param Buffer Pointer to the data buffer to store the data read from the serial device.\r
eceb3a4c 67 @param NumberOfBytes Number of bytes which will be read.\r
fd7a76af 68\r
1a2f870c 69 @retval 0 Read data failed, no data is to be read.\r
28d3e14f 70 @retval >0 Actual number of bytes read from serial device.\r
fd7a76af 71\r
72**/\r
73UINTN\r
74EFIAPI\r
75SerialPortRead (\r
2f88bd3a
MK
76 OUT UINT8 *Buffer,\r
77 IN UINTN NumberOfBytes\r
ef4ce186 78 );\r
fd7a76af 79\r
a2ddd00b 80/**\r
07974e78 81 Polls a serial device to see if there is any data waiting to be read.\r
a2ddd00b 82\r
28d3e14f 83 Polls a serial device to see if there is any data waiting to be read.\r
07974e78 84 If there is data waiting to be read from the serial device, then TRUE is returned.\r
85 If there is no data waiting to be read from the serial device, then FALSE is returned.\r
a2ddd00b 86\r
07974e78 87 @retval TRUE Data is waiting to be read from the serial device.\r
88 @retval FALSE There is no data waiting to be read from the serial device.\r
a2ddd00b
LG
89\r
90**/\r
91BOOLEAN\r
92EFIAPI\r
93SerialPortPoll (\r
94 VOID\r
95 );\r
fd7a76af 96\r
8d9325de
SZ
97/**\r
98 Sets the control bits on a serial device.\r
99\r
100 @param Control Sets the bits of Control that are settable.\r
101\r
102 @retval RETURN_SUCCESS The new control bits were set on the serial device.\r
103 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
104 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
105\r
106**/\r
107RETURN_STATUS\r
108EFIAPI\r
109SerialPortSetControl (\r
2f88bd3a 110 IN UINT32 Control\r
8d9325de
SZ
111 );\r
112\r
113/**\r
114 Retrieve the status of the control bits on a serial device.\r
115\r
116 @param Control A pointer to return the current control signals from the serial device.\r
117\r
118 @retval RETURN_SUCCESS The control bits were read from the serial device.\r
119 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
120 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
121\r
122**/\r
123RETURN_STATUS\r
124EFIAPI\r
125SerialPortGetControl (\r
2f88bd3a 126 OUT UINT32 *Control\r
8d9325de
SZ
127 );\r
128\r
129/**\r
130 Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,\r
131 data bits, and stop bits on a serial device.\r
132\r
133 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the\r
134 device's default interface speed.\r
135 On output, the value actually set.\r
136 @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the\r
137 serial interface. A ReceiveFifoDepth value of 0 will use\r
138 the device's default FIFO depth.\r
139 On output, the value actually set.\r
140 @param Timeout The requested time out for a single character in microseconds.\r
141 This timeout applies to both the transmit and receive side of the\r
142 interface. A Timeout value of 0 will use the device's default time\r
143 out value.\r
144 On output, the value actually set.\r
145 @param Parity The type of parity to use on this serial device. A Parity value of\r
146 DefaultParity will use the device's default parity value.\r
147 On output, the value actually set.\r
148 @param DataBits The number of data bits to use on the serial device. A DataBits\r
149 vaule of 0 will use the device's default data bit setting.\r
150 On output, the value actually set.\r
151 @param StopBits The number of stop bits to use on this serial device. A StopBits\r
152 value of DefaultStopBits will use the device's default number of\r
153 stop bits.\r
154 On output, the value actually set.\r
155\r
156 @retval RETURN_SUCCESS The new attributes were set on the serial device.\r
157 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
158 @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.\r
159 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
160\r
161**/\r
162RETURN_STATUS\r
163EFIAPI\r
164SerialPortSetAttributes (\r
2f88bd3a
MK
165 IN OUT UINT64 *BaudRate,\r
166 IN OUT UINT32 *ReceiveFifoDepth,\r
167 IN OUT UINT32 *Timeout,\r
168 IN OUT EFI_PARITY_TYPE *Parity,\r
169 IN OUT UINT8 *DataBits,\r
170 IN OUT EFI_STOP_BITS_TYPE *StopBits\r
8d9325de
SZ
171 );\r
172\r
fd7a76af 173#endif\r