]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/Library/DxeEmuSerialPortLib/DxeEmuSerialPortLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / EmulatorPkg / Library / DxeEmuSerialPortLib / DxeEmuSerialPortLib.c
CommitLineData
949f388f 1/** @file\r
d18d8a1d 2 Serial Port Lib that thunks back to Emulator services to write to StdErr.\r
3 All read functions are stubed out.\r
949f388f 4\r
9fffd8e2 5 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
949f388f 6 Portions copyright (c) 2011, Apple Inc. All rights reserved.<BR>\r
e3ba31da 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
949f388f 8\r
9**/\r
10\r
949f388f 11#include <PiDxe.h>\r
12#include <Library/SerialPortLib.h>\r
13#include <Library/EmuThunkLib.h>\r
14\r
949f388f 15/**\r
16 Initialize the serial device hardware.\r
d18d8a1d 17\r
949f388f 18 If no initialization is required, then return RETURN_SUCCESS.\r
19 If the serial device was successfully initialized, then return RETURN_SUCCESS.\r
20 If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.\r
d18d8a1d 21\r
949f388f 22 @retval RETURN_SUCCESS The serial device was initialized.\r
23 @retval RETURN_DEVICE_ERROR The serial device could not be initialized.\r
24\r
25**/\r
26RETURN_STATUS\r
27EFIAPI\r
28SerialPortInitialize (\r
29 VOID\r
30 )\r
31{\r
7e284acb 32 return gEmuThunk->ConfigStdIn ();\r
949f388f 33}\r
34\r
35/**\r
d18d8a1d 36 Write data from buffer to serial device.\r
37\r
38 Writes NumberOfBytes data bytes from Buffer to the serial device.\r
949f388f 39 The number of bytes actually written to the serial device is returned.\r
40 If the return value is less than NumberOfBytes, then the write operation failed.\r
d18d8a1d 41 If Buffer is NULL, then ASSERT().\r
949f388f 42 If NumberOfBytes is zero, then return 0.\r
43\r
44 @param Buffer The pointer to the data buffer to be written.\r
45 @param NumberOfBytes The number of bytes to written to the serial device.\r
46\r
47 @retval 0 NumberOfBytes is 0.\r
d18d8a1d 48 @retval >0 The number of bytes written to the serial device.\r
949f388f 49 If this value is less than NumberOfBytes, then the read operation failed.\r
50\r
51**/\r
52UINTN\r
53EFIAPI\r
54SerialPortWrite (\r
a550d468
MK
55 IN UINT8 *Buffer,\r
56 IN UINTN NumberOfBytes\r
949f388f 57 )\r
58{\r
7e284acb 59 return gEmuThunk->WriteStdOut (Buffer, NumberOfBytes);\r
949f388f 60}\r
61\r
949f388f 62/**\r
63 Read data from serial device and save the datas in buffer.\r
d18d8a1d 64\r
949f388f 65 Reads NumberOfBytes data bytes from a serial device into the buffer\r
d18d8a1d 66 specified by Buffer. The number of bytes actually read is returned.\r
949f388f 67 If the return value is less than NumberOfBytes, then the rest operation failed.\r
d18d8a1d 68 If Buffer is NULL, then ASSERT().\r
949f388f 69 If NumberOfBytes is zero, then return 0.\r
70\r
71 @param Buffer The pointer to the data buffer to store the data read from the serial device.\r
72 @param NumberOfBytes The number of bytes which will be read.\r
73\r
74 @retval 0 Read data failed; No data is to be read.\r
75 @retval >0 The actual number of bytes read from serial device.\r
76\r
77**/\r
78UINTN\r
79EFIAPI\r
80SerialPortRead (\r
a550d468
MK
81 OUT UINT8 *Buffer,\r
82 IN UINTN NumberOfBytes\r
949f388f 83 )\r
84{\r
7e284acb 85 return gEmuThunk->ReadStdIn (Buffer, NumberOfBytes);\r
949f388f 86}\r
87\r
88/**\r
89 Polls a serial device to see if there is any data waiting to be read.\r
90\r
91 Polls a serial device to see if there is any data waiting to be read.\r
92 If there is data waiting to be read from the serial device, then TRUE is returned.\r
93 If there is no data waiting to be read from the serial device, then FALSE is returned.\r
94\r
95 @retval TRUE Data is waiting to be read from the serial device.\r
96 @retval FALSE There is no data waiting to be read from the serial device.\r
97\r
98**/\r
99BOOLEAN\r
100EFIAPI\r
101SerialPortPoll (\r
102 VOID\r
103 )\r
104{\r
7e284acb 105 return gEmuThunk->PollStdIn ();\r
949f388f 106}\r
107\r
9fffd8e2
SZ
108/**\r
109 Sets the control bits on a serial device.\r
110\r
111 @param Control Sets the bits of Control that are settable.\r
112\r
113 @retval RETURN_SUCCESS The new control bits were set on the serial device.\r
114 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
115 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
116\r
117**/\r
118RETURN_STATUS\r
119EFIAPI\r
120SerialPortSetControl (\r
a550d468 121 IN UINT32 Control\r
9fffd8e2
SZ
122 )\r
123{\r
124 return RETURN_UNSUPPORTED;\r
125}\r
126\r
127/**\r
128 Retrieve the status of the control bits on a serial device.\r
129\r
130 @param Control A pointer to return the current control signals from the serial device.\r
131\r
132 @retval RETURN_SUCCESS The control bits were read from the serial device.\r
133 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
134 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
135\r
136**/\r
137RETURN_STATUS\r
138EFIAPI\r
139SerialPortGetControl (\r
a550d468 140 OUT UINT32 *Control\r
9fffd8e2
SZ
141 )\r
142{\r
143 *Control = 0;\r
144 if (!SerialPortPoll ()) {\r
145 *Control = EFI_SERIAL_INPUT_BUFFER_EMPTY;\r
146 }\r
a550d468 147\r
9fffd8e2
SZ
148 return RETURN_SUCCESS;\r
149}\r
150\r
151/**\r
152 Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,\r
153 data bits, and stop bits on a serial device.\r
154\r
155 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the\r
156 device's default interface speed.\r
157 On output, the value actually set.\r
158 @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the\r
159 serial interface. A ReceiveFifoDepth value of 0 will use\r
160 the device's default FIFO depth.\r
161 On output, the value actually set.\r
162 @param Timeout The requested time out for a single character in microseconds.\r
163 This timeout applies to both the transmit and receive side of the\r
164 interface. A Timeout value of 0 will use the device's default time\r
165 out value.\r
166 On output, the value actually set.\r
167 @param Parity The type of parity to use on this serial device. A Parity value of\r
168 DefaultParity will use the device's default parity value.\r
169 On output, the value actually set.\r
170 @param DataBits The number of data bits to use on the serial device. A DataBits\r
171 vaule of 0 will use the device's default data bit setting.\r
172 On output, the value actually set.\r
173 @param StopBits The number of stop bits to use on this serial device. A StopBits\r
174 value of DefaultStopBits will use the device's default number of\r
175 stop bits.\r
176 On output, the value actually set.\r
177\r
178 @retval RETURN_SUCCESS The new attributes were set on the serial device.\r
179 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
180 @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.\r
181 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
182\r
183**/\r
184RETURN_STATUS\r
185EFIAPI\r
186SerialPortSetAttributes (\r
a550d468
MK
187 IN OUT UINT64 *BaudRate,\r
188 IN OUT UINT32 *ReceiveFifoDepth,\r
189 IN OUT UINT32 *Timeout,\r
190 IN OUT EFI_PARITY_TYPE *Parity,\r
191 IN OUT UINT8 *DataBits,\r
192 IN OUT EFI_STOP_BITS_TYPE *StopBits\r
9fffd8e2
SZ
193 )\r
194{\r
195 return RETURN_UNSUPPORTED;\r
196}\r