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