TianoCore EDK2 master
Loading...
Searching...
No Matches
CbSerialPortLib.c
Go to the documentation of this file.
1
9#include <Base.h>
10#include <Coreboot.h>
11
13#include <Library/BlParseLib.h>
15
16// Upper nibble contains flags
17#define CBMC_CURSOR_MASK ((1 << 28) - 1)
18#define CBMC_OVERFLOW (1 << 31)
19
20STATIC struct cbmem_console *mCbConsole = NULL;
21
33VOID *
35 IN UINT32 Tag
36 );
37
49RETURN_STATUS
50EFIAPI
52 VOID
53 )
54{
55 struct cb_cbmem_ref *CbMemRef;
56
57 // The coreboot table contains large structures as references
58 CbMemRef = FindCbTag (CB_TAG_CBMEM_CONSOLE);
59 if (CbMemRef == NULL) {
61 }
62
63 mCbConsole = (VOID *)(UINTN)CbMemRef->cbmem_addr; // Support PEI and DXE
64 if (mCbConsole == NULL) {
66 }
67
68 return RETURN_SUCCESS;
69}
70
89EFIAPI
91 IN UINT8 *Buffer,
92 IN UINTN NumberOfBytes
93 )
94{
95 UINT32 Cursor;
96 UINT32 Flags;
97
98 if ((Buffer == NULL) || (NumberOfBytes == 0)) {
99 return 0;
100 }
101
102 if (mCbConsole == NULL) {
103 return 0;
104 }
105
106 Cursor = mCbConsole->cursor & CBMC_CURSOR_MASK;
107 Flags = mCbConsole->cursor & ~CBMC_CURSOR_MASK;
108 if (Cursor >= mCbConsole->size) {
109 // Already overflowed; bail out. TODO: Is this unnecessarily cautious?
110 // - Supports old coreboot version with legacy overflow mechanism.
111 return 0;
112 }
113
114 if (Cursor + NumberOfBytes > mCbConsole->size) {
115 // Will overflow, zero cursor and set flag.
116 Cursor = 0;
117 Flags |= CBMC_OVERFLOW;
118 }
119
120 if (NumberOfBytes > mCbConsole->size) {
121 // This one debug message is longer than the entire buffer. Truncate it.
122 // - TODO: Is this unnecessarily cautious?
123 NumberOfBytes = mCbConsole->size;
124 }
125
126 CopyMem (&mCbConsole->body[Cursor], Buffer, NumberOfBytes);
127 Cursor += NumberOfBytes;
128
129 if (Cursor == mCbConsole->size) {
130 // Next message will overflow, zero cursor.
131 // - Set flag preemptively. This could not be determined later.
132 Cursor = 0;
133 Flags |= CBMC_OVERFLOW;
134 }
135
136 mCbConsole->cursor = Flags | Cursor;
137
138 return NumberOfBytes;
139}
140
156UINTN
157EFIAPI
159 OUT UINT8 *Buffer,
160 IN UINTN NumberOfBytes
161 )
162{
163 return 0;
164}
165
173BOOLEAN
174EFIAPI
176 VOID
177 )
178{
179 return FALSE;
180}
181
192RETURN_STATUS
193EFIAPI
195 IN UINT32 Control
196 )
197{
198 return RETURN_UNSUPPORTED;
199}
200
211RETURN_STATUS
212EFIAPI
214 OUT UINT32 *Control
215 )
216{
217 return RETURN_UNSUPPORTED;
218}
219
253RETURN_STATUS
254EFIAPI
256 IN OUT UINT64 *BaudRate,
257 IN OUT UINT32 *ReceiveFifoDepth,
258 IN OUT UINT32 *Timeout,
259 IN OUT EFI_PARITY_TYPE *Parity,
260 IN OUT UINT8 *DataBits,
261 IN OUT EFI_STOP_BITS_TYPE *StopBits
262 )
263{
264 return RETURN_UNSUPPORTED;
265}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID * FindCbTag(IN UINT32 Tag)
Definition: CbParseLib.c:210
BOOLEAN EFIAPI SerialPortPoll(VOID)
RETURN_STATUS EFIAPI SerialPortSetAttributes(IN OUT UINT64 *BaudRate, IN OUT UINT32 *ReceiveFifoDepth, IN OUT UINT32 *Timeout, IN OUT EFI_PARITY_TYPE *Parity, IN OUT UINT8 *DataBits, IN OUT EFI_STOP_BITS_TYPE *StopBits)
UINTN EFIAPI SerialPortRead(OUT UINT8 *Buffer, IN UINTN NumberOfBytes)
RETURN_STATUS EFIAPI SerialPortInitialize(VOID)
RETURN_STATUS EFIAPI SerialPortSetControl(IN UINT32 Control)
RETURN_STATUS EFIAPI SerialPortGetControl(OUT UINT32 *Control)
UINTN EFIAPI SerialPortWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define RETURN_DEVICE_ERROR
Definition: Base.h:1104
#define RETURN_UNSUPPORTED
Definition: Base.h:1081
#define RETURN_SUCCESS
Definition: Base.h:1066
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STOP_BITS_TYPE
Definition: SerialIo.h:53
EFI_PARITY_TYPE
Definition: SerialIo.h:41