]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.c
EmulatorPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmulatorPkg / Library / PeiEmuSerialPortLib / PeiEmuSerialPortLib.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. There is no constructor so this lib can\r
949f388f 4 be linked with PEI Core.\r
5\r
6 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
7 Portions copyright (c) 2011, Apple Inc. All rights reserved.<BR>\r
e3ba31da 8 SPDX-License-Identifier: BSD-2-Clause-Patent\r
949f388f 9\r
10**/\r
11\r
12\r
13#include <PiPei.h>\r
14#include <Library/SerialPortLib.h>\r
15#include <Library/PeiServicesLib.h>\r
16\r
17#include <Ppi/EmuThunk.h>\r
18#include <Protocol/EmuThunk.h>\r
19\r
20\r
21\r
22/**\r
23 Initialize the serial device hardware.\r
d18d8a1d 24\r
949f388f 25 If no initialization is required, then return RETURN_SUCCESS.\r
26 If the serial device was successfully initialized, then return RETURN_SUCCESS.\r
27 If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.\r
d18d8a1d 28\r
949f388f 29 @retval RETURN_SUCCESS The serial device was initialized.\r
30 @retval RETURN_DEVICE_ERROR The serial device could not be initialized.\r
31\r
32**/\r
33RETURN_STATUS\r
34EFIAPI\r
35SerialPortInitialize (\r
36 VOID\r
37 )\r
38{\r
39 return RETURN_SUCCESS;\r
40}\r
41\r
42/**\r
d18d8a1d 43 Write data from buffer to serial device.\r
44\r
45 Writes NumberOfBytes data bytes from Buffer to the serial device.\r
949f388f 46 The number of bytes actually written to the serial device is returned.\r
47 If the return value is less than NumberOfBytes, then the write operation failed.\r
d18d8a1d 48 If Buffer is NULL, then ASSERT().\r
949f388f 49 If NumberOfBytes is zero, then return 0.\r
50\r
51 @param Buffer The pointer to the data buffer to be written.\r
52 @param NumberOfBytes The number of bytes to written to the serial device.\r
53\r
54 @retval 0 NumberOfBytes is 0.\r
d18d8a1d 55 @retval >0 The number of bytes written to the serial device.\r
949f388f 56 If this value is less than NumberOfBytes, then the read operation failed.\r
57\r
58**/\r
59UINTN\r
60EFIAPI\r
61SerialPortWrite (\r
62 IN UINT8 *Buffer,\r
63 IN UINTN NumberOfBytes\r
64 )\r
65{\r
66 EMU_THUNK_PPI *ThunkPpi;\r
67 EFI_STATUS Status;\r
68 EMU_THUNK_PROTOCOL *Thunk;\r
69\r
70 //\r
71 // Locate EmuThunkPpi for retrieving standard output handle\r
72 //\r
73 Status = PeiServicesLocatePpi (\r
74 &gEmuThunkPpiGuid,\r
75 0,\r
76 NULL,\r
77 (VOID **) &ThunkPpi\r
78 );\r
79 if (!EFI_ERROR (Status)) {\r
80 Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();\r
81 return Thunk->WriteStdErr (Buffer, NumberOfBytes);\r
82 }\r
d18d8a1d 83\r
949f388f 84 return 0;\r
85}\r
86\r
87\r
88/**\r
89 Read data from serial device and save the datas in buffer.\r
d18d8a1d 90\r
949f388f 91 Reads NumberOfBytes data bytes from a serial device into the buffer\r
d18d8a1d 92 specified by Buffer. The number of bytes actually read is returned.\r
949f388f 93 If the return value is less than NumberOfBytes, then the rest operation failed.\r
d18d8a1d 94 If Buffer is NULL, then ASSERT().\r
949f388f 95 If NumberOfBytes is zero, then return 0.\r
96\r
97 @param Buffer The pointer to the data buffer to store the data read from the serial device.\r
98 @param NumberOfBytes The number of bytes which will be read.\r
99\r
100 @retval 0 Read data failed; No data is to be read.\r
101 @retval >0 The actual number of bytes read from serial device.\r
102\r
103**/\r
104UINTN\r
105EFIAPI\r
106SerialPortRead (\r
107 OUT UINT8 *Buffer,\r
108 IN UINTN NumberOfBytes\r
109 )\r
110{\r
111 return 0;\r
112}\r
113\r
114/**\r
115 Polls a serial device to see if there is any data waiting to be read.\r
116\r
117 Polls a serial device to see if there is any data waiting to be read.\r
118 If there is data waiting to be read from the serial device, then TRUE is returned.\r
119 If there is no data waiting to be read from the serial device, then FALSE is returned.\r
120\r
121 @retval TRUE Data is waiting to be read from the serial device.\r
122 @retval FALSE There is no data waiting to be read from the serial device.\r
123\r
124**/\r
125BOOLEAN\r
126EFIAPI\r
127SerialPortPoll (\r
128 VOID\r
129 )\r
130{\r
131 return FALSE;\r
132}\r
133\r