]> git.proxmox.com Git - mirror_edk2.git/blob - InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.c
Add InOsEmuPkg. Like UnixPkg and Nt32Pkg, but EFI code can be common and does not...
[mirror_edk2.git] / InOsEmuPkg / 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/PeiServicesLib.h>
22
23 #include <Ppi/EmuThunk.h>
24 #include <Protocol/EmuThunk.h>
25
26
27
28 /**
29 Initialize the serial device hardware.
30
31 If no initialization is required, then return RETURN_SUCCESS.
32 If the serial device was successfully initialized, then return RETURN_SUCCESS.
33 If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
34
35 @retval RETURN_SUCCESS The serial device was initialized.
36 @retval RETURN_DEVICE_ERROR The serial device could not be initialized.
37
38 **/
39 RETURN_STATUS
40 EFIAPI
41 SerialPortInitialize (
42 VOID
43 )
44 {
45 return RETURN_SUCCESS;
46 }
47
48 /**
49 Write data from buffer to serial device.
50
51 Writes NumberOfBytes data bytes from Buffer to the serial device.
52 The number of bytes actually written to the serial device is returned.
53 If the return value is less than NumberOfBytes, then the write operation failed.
54 If Buffer is NULL, then ASSERT().
55 If NumberOfBytes is zero, then return 0.
56
57 @param Buffer The pointer to the data buffer to be written.
58 @param NumberOfBytes The number of bytes to written to the serial device.
59
60 @retval 0 NumberOfBytes is 0.
61 @retval >0 The number of bytes written to the serial device.
62 If this value is less than NumberOfBytes, then the read operation failed.
63
64 **/
65 UINTN
66 EFIAPI
67 SerialPortWrite (
68 IN UINT8 *Buffer,
69 IN UINTN NumberOfBytes
70 )
71 {
72 EMU_THUNK_PPI *ThunkPpi;
73 EFI_STATUS Status;
74 EMU_THUNK_PROTOCOL *Thunk;
75
76 //
77 // Locate EmuThunkPpi for retrieving standard output handle
78 //
79 Status = PeiServicesLocatePpi (
80 &gEmuThunkPpiGuid,
81 0,
82 NULL,
83 (VOID **) &ThunkPpi
84 );
85 if (!EFI_ERROR (Status)) {
86 Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();
87 return Thunk->WriteStdErr (Buffer, NumberOfBytes);
88 }
89
90 return 0;
91 }
92
93
94 /**
95 Read data from serial device and save the datas in buffer.
96
97 Reads NumberOfBytes data bytes from a serial device into the buffer
98 specified by Buffer. The number of bytes actually read is returned.
99 If the return value is less than NumberOfBytes, then the rest operation failed.
100 If Buffer is NULL, then ASSERT().
101 If NumberOfBytes is zero, then return 0.
102
103 @param Buffer The pointer to the data buffer to store the data read from the serial device.
104 @param NumberOfBytes The number of bytes which will be read.
105
106 @retval 0 Read data failed; No data is to be read.
107 @retval >0 The actual number of bytes read from serial device.
108
109 **/
110 UINTN
111 EFIAPI
112 SerialPortRead (
113 OUT UINT8 *Buffer,
114 IN UINTN NumberOfBytes
115 )
116 {
117 return 0;
118 }
119
120 /**
121 Polls a serial device to see if there is any data waiting to be read.
122
123 Polls a serial device to see if there is any data waiting to be read.
124 If there is data waiting to be read from the serial device, then TRUE is returned.
125 If there is no data waiting to be read from the serial device, then FALSE is returned.
126
127 @retval TRUE Data is waiting to be read from the serial device.
128 @retval FALSE There is no data waiting to be read from the serial device.
129
130 **/
131 BOOLEAN
132 EFIAPI
133 SerialPortPoll (
134 VOID
135 )
136 {
137 return FALSE;
138 }
139
140