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