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