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 - 2010, 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
SerialPortInitialize(VOID)32 SerialPortInitialize (
33   VOID
34   )
35 {
36   return RETURN_SUCCESS;
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
SerialPortWrite(IN UINT8 * Buffer,IN UINTN NumberOfBytes)58 SerialPortWrite (
59   IN UINT8     *Buffer,
60   IN UINTN     NumberOfBytes
61   )
62 {
63   if (gEmuThunk == NULL) {
64     return NumberOfBytes;
65   }
66 
67   return gEmuThunk->WriteStdErr (Buffer, NumberOfBytes);
68 }
69 
70 
71 /**
72   Read data from serial device and save the datas in buffer.
73 
74   Reads NumberOfBytes data bytes from a serial device into the buffer
75   specified by Buffer. The number of bytes actually read is returned.
76   If the return value is less than NumberOfBytes, then the rest operation failed.
77   If Buffer is NULL, then ASSERT().
78   If NumberOfBytes is zero, then return 0.
79 
80   @param  Buffer           The pointer to the data buffer to store the data read from the serial device.
81   @param  NumberOfBytes    The number of bytes which will be read.
82 
83   @retval 0                Read data failed; No data is to be read.
84   @retval >0               The actual number of bytes read from serial device.
85 
86 **/
87 UINTN
88 EFIAPI
SerialPortRead(OUT UINT8 * Buffer,IN UINTN NumberOfBytes)89 SerialPortRead (
90   OUT UINT8     *Buffer,
91   IN  UINTN     NumberOfBytes
92   )
93 {
94   return 0;
95 }
96 
97 /**
98   Polls a serial device to see if there is any data waiting to be read.
99 
100   Polls a serial device to see if there is any data waiting to be read.
101   If there is data waiting to be read from the serial device, then TRUE is returned.
102   If there is no data waiting to be read from the serial device, then FALSE is returned.
103 
104   @retval TRUE             Data is waiting to be read from the serial device.
105   @retval FALSE            There is no data waiting to be read from the serial device.
106 
107 **/
108 BOOLEAN
109 EFIAPI
SerialPortPoll(VOID)110 SerialPortPoll (
111   VOID
112   )
113 {
114   return FALSE;
115 }
116 
117 
118