]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.c
Sync with EmulatorPkg changes.
[mirror_edk2.git] / EmulatorPkg / Library / PeiEmuSerialPortLib / PeiEmuSerialPortLib.c
1 /** @file
2 Serial Port Lib that thunks back to Emulator services to write to StdErr.
3 All read functions are stubed out. There is no constructor so this lib can
4 be linked with PEI Core.
5
6 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
7 Portions copyright (c) 2011, Apple Inc. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php.
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18
19 #include <PiPei.h>
20 #include <Library/SerialPortLib.h>
21 #include <Library/SerialPortExtLib.h>
22 #include <Library/PeiServicesLib.h>
23
24 #include <Ppi/EmuThunk.h>
25 #include <Protocol/EmuThunk.h>
26
27
28
29 /**
30 Initialize the serial device hardware.
31
32 If no initialization is required, then return RETURN_SUCCESS.
33 If the serial device was successfully initialized, then return RETURN_SUCCESS.
34 If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
35
36 @retval RETURN_SUCCESS The serial device was initialized.
37 @retval RETURN_DEVICE_ERROR The serial device could not be initialized.
38
39 **/
40 RETURN_STATUS
41 EFIAPI
42 SerialPortInitialize (
43 VOID
44 )
45 {
46 return RETURN_SUCCESS;
47 }
48
49 /**
50 Write data from buffer to serial device.
51
52 Writes NumberOfBytes data bytes from Buffer to the serial device.
53 The number of bytes actually written to the serial device is returned.
54 If the return value is less than NumberOfBytes, then the write operation failed.
55 If Buffer is NULL, then ASSERT().
56 If NumberOfBytes is zero, then return 0.
57
58 @param Buffer The pointer to the data buffer to be written.
59 @param NumberOfBytes The number of bytes to written to the serial device.
60
61 @retval 0 NumberOfBytes is 0.
62 @retval >0 The number of bytes written to the serial device.
63 If this value is less than NumberOfBytes, then the read operation failed.
64
65 **/
66 UINTN
67 EFIAPI
68 SerialPortWrite (
69 IN UINT8 *Buffer,
70 IN UINTN NumberOfBytes
71 )
72 {
73 EMU_THUNK_PPI *ThunkPpi;
74 EFI_STATUS Status;
75 EMU_THUNK_PROTOCOL *Thunk;
76
77 //
78 // Locate EmuThunkPpi for retrieving standard output handle
79 //
80 Status = PeiServicesLocatePpi (
81 &gEmuThunkPpiGuid,
82 0,
83 NULL,
84 (VOID **) &ThunkPpi
85 );
86 if (!EFI_ERROR (Status)) {
87 Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();
88 return Thunk->WriteStdErr (Buffer, NumberOfBytes);
89 }
90
91 return 0;
92 }
93
94
95 /**
96 Read data from serial device and save the datas in buffer.
97
98 Reads NumberOfBytes data bytes from a serial device into the buffer
99 specified by Buffer. The number of bytes actually read is returned.
100 If the return value is less than NumberOfBytes, then the rest operation failed.
101 If Buffer is NULL, then ASSERT().
102 If NumberOfBytes is zero, then return 0.
103
104 @param Buffer The pointer to the data buffer to store the data read from the serial device.
105 @param NumberOfBytes The number of bytes which will be read.
106
107 @retval 0 Read data failed; No data is to be read.
108 @retval >0 The actual number of bytes read from serial device.
109
110 **/
111 UINTN
112 EFIAPI
113 SerialPortRead (
114 OUT UINT8 *Buffer,
115 IN UINTN NumberOfBytes
116 )
117 {
118 return 0;
119 }
120
121 /**
122 Polls a serial device to see if there is any data waiting to be read.
123
124 Polls a serial device to see if there is any data waiting to be read.
125 If there is data waiting to be read from the serial device, then TRUE is returned.
126 If there is no data waiting to be read from the serial device, then FALSE is returned.
127
128 @retval TRUE Data is waiting to be read from the serial device.
129 @retval FALSE There is no data waiting to be read from the serial device.
130
131 **/
132 BOOLEAN
133 EFIAPI
134 SerialPortPoll (
135 VOID
136 )
137 {
138 return FALSE;
139 }
140
141 /**
142 Set the serial device control bits.
143
144 @return Always return EFI_UNSUPPORTED.
145
146 **/
147 RETURN_STATUS
148 EFIAPI
149 SerialPortSetControl (
150 IN UINT32 Control
151 )
152 {
153 return RETURN_SUCCESS;
154 }
155
156 /**
157 Get the serial device control bits.
158
159 @param Control Control signals read from the serial device.
160
161 @retval EFI_SUCCESS The control bits were read from the serial device.
162 @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.
163
164 **/
165 RETURN_STATUS
166 EFIAPI
167 SerialPortGetControl (
168 OUT UINT32 *Control
169 )
170 {
171 return RETURN_SUCCESS;
172 }
173
174
175 /**
176 Set the serial device attributes.
177
178 @return Always return EFI_UNSUPPORTED.
179
180 **/
181 RETURN_STATUS
182 EFIAPI
183 SerialPortSetAttributes (
184 IN UINT64 BaudRate,
185 IN UINT32 ReceiveFifoDepth,
186 IN UINT32 Timeout,
187 IN EFI_PARITY_TYPE Parity,
188 IN UINT8 DataBits,
189 IN EFI_STOP_BITS_TYPE StopBits
190 )
191 {
192 return RETURN_SUCCESS;
193 }
194
195