Skip to content

Commit

Permalink
MdeModulePkg: TerminalDxe: Extending the FIFO size
Browse files Browse the repository at this point in the history
This change extended the size of FIFO for querying serial console.

For devices supporting higher baudrate, this will allow more message to
be buffered when the incoming stream is too high.
  • Loading branch information
kuqin12 authored and kenlautner committed May 9, 2023
1 parent 0ccaa44 commit 69909c3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 57 deletions.
23 changes: 13 additions & 10 deletions MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,28 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/PcdLib.h>
#include <Library/BaseLib.h>

#define RAW_FIFO_MAX_NUMBER 255
#define FIFO_MAX_NUMBER 128
// MU_CHANGE Starts: Extending the FIFO buffer size beyond UINT8 width.
#define RAW_FIFO_MAX_NUMBER 600
#define FIFO_MAX_NUMBER 300

typedef struct {
UINT8 Head;
UINT8 Tail;
UINT8 Data[RAW_FIFO_MAX_NUMBER + 1];
UINT16 Head;
UINT16 Tail;
UINT8 Data[RAW_FIFO_MAX_NUMBER + 1];
} RAW_DATA_FIFO;

typedef struct {
UINT8 Head;
UINT8 Tail;
UINT16 Head;
UINT16 Tail;
UINT16 Data[FIFO_MAX_NUMBER + 1];
} UNICODE_FIFO;

typedef struct {
UINT8 Head;
UINT8 Tail;
UINT16 Head;
UINT16 Tail;
EFI_INPUT_KEY Data[FIFO_MAX_NUMBER + 1];
} EFI_KEY_FIFO;
// MU_CHANGE Ends

typedef struct {
UINTN Columns;
Expand Down Expand Up @@ -880,7 +882,8 @@ SetTerminalDevicePath (
EFI_STATUS
GetOneKeyFromSerial (
EFI_SERIAL_IO_PROTOCOL *SerialIo,
UINT8 *Input
UINT8 *Output,
UINTN *Size // MU_CHANGE Starts: Extending the FIFO buffer size beyond UINT8 width.
);

/**
Expand Down
99 changes: 52 additions & 47 deletions MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ TerminalConInTimerHandler (
EFI_STATUS Status;
TERMINAL_DEV *TerminalDevice;
UINT32 Control;
UINT8 Input;
UINT8 Input[RAW_FIFO_MAX_NUMBER];
EFI_SERIAL_IO_MODE *Mode;
EFI_SERIAL_IO_PROTOCOL *SerialIo;
UINTN SerialInTimeOut;
Expand Down Expand Up @@ -562,23 +562,27 @@ TerminalConInTimerHandler (
// Fetch all the keys in the serial buffer,
// and insert the byte stream into RawFIFO.
//
while (!IsRawFiFoFull (TerminalDevice)) {
Status = GetOneKeyFromSerial (TerminalDevice->SerialIo, &Input);

if (EFI_ERROR (Status)) {
if (Status == EFI_DEVICE_ERROR) {
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
EFI_ERROR_CODE | EFI_ERROR_MINOR,
(EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_INPUT_ERROR),
TerminalDevice->DevicePath
);
}

break;
// MU_CHANGE Starts: Keep getting all available serial keys until we exhaust the FIFO.
UINTN Size = RAW_FIFO_MAX_NUMBER;
Status = GetOneKeyFromSerial (TerminalDevice->SerialIo, Input, &Size);
if (EFI_ERROR (Status)) {
if (Status == EFI_DEVICE_ERROR) {
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
EFI_ERROR_CODE | EFI_ERROR_MINOR,
(EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_INPUT_ERROR),
TerminalDevice->DevicePath
);
}

RawFiFoInsertOneKey (TerminalDevice, Input);
return;
}

UINTN i = 0;
while (i < Size && !IsRawFiFoFull (TerminalDevice)) {
RawFiFoInsertOneKey (TerminalDevice, Input[i++]);
}

// MU_CHANGE Ends
}

//
Expand Down Expand Up @@ -657,25 +661,26 @@ KeyNotifyProcessHandler (
EFI_STATUS
GetOneKeyFromSerial (
EFI_SERIAL_IO_PROTOCOL *SerialIo,
UINT8 *Output
UINT8 *Output,
// MU_CHANGE Starts: Extending the FIFO buffer size beyond UINT8 width.
UINTN *Size
)
{
EFI_STATUS Status;
UINTN Size;

Size = 1;
*Output = 0;

//
// Read one key from serial I/O device.
//
Status = SerialIo->Read (SerialIo, &Size, Output);
Status = SerialIo->Read (SerialIo, Size, Output);

if (EFI_ERROR (Status)) {
if (Status == EFI_TIMEOUT) {
return EFI_NOT_READY;
}
if (Status == EFI_TIMEOUT) {
return EFI_SUCCESS;
}

if (EFI_ERROR (Status)) {
// MU_CHANGE Ends.
return EFI_DEVICE_ERROR;
}

Expand Down Expand Up @@ -703,7 +708,7 @@ RawFiFoInsertOneKey (
UINT8 Input
)
{
UINT8 Tail;
UINT16 Tail; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

Tail = TerminalDevice->RawFiFo->Tail;

Expand All @@ -716,7 +721,7 @@ RawFiFoInsertOneKey (

TerminalDevice->RawFiFo->Data[Tail] = Input;

TerminalDevice->RawFiFo->Tail = (UINT8)((Tail + 1) % (RAW_FIFO_MAX_NUMBER + 1));
TerminalDevice->RawFiFo->Tail = (UINT16)((Tail + 1) % (RAW_FIFO_MAX_NUMBER + 1)); // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

return TRUE;
}
Expand All @@ -737,7 +742,7 @@ RawFiFoRemoveOneKey (
UINT8 *Output
)
{
UINT8 Head;
UINT16 Head; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

Head = TerminalDevice->RawFiFo->Head;

Expand All @@ -751,7 +756,7 @@ RawFiFoRemoveOneKey (

*Output = TerminalDevice->RawFiFo->Data[Head];

TerminalDevice->RawFiFo->Head = (UINT8)((Head + 1) % (RAW_FIFO_MAX_NUMBER + 1));
TerminalDevice->RawFiFo->Head = (UINT16)((Head + 1) % (RAW_FIFO_MAX_NUMBER + 1)); // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

return TRUE;
}
Expand Down Expand Up @@ -791,8 +796,8 @@ IsRawFiFoFull (
TERMINAL_DEV *TerminalDevice
)
{
UINT8 Tail;
UINT8 Head;
UINT16 Tail; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.
UINT16 Head; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

Tail = TerminalDevice->RawFiFo->Tail;
Head = TerminalDevice->RawFiFo->Head;
Expand Down Expand Up @@ -821,7 +826,7 @@ EfiKeyFiFoForNotifyInsertOneKey (
EFI_INPUT_KEY *Input
)
{
UINT8 Tail;
UINT16 Tail; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

Tail = EfiKeyFiFo->Tail;

Expand All @@ -834,7 +839,7 @@ EfiKeyFiFoForNotifyInsertOneKey (

CopyMem (&EfiKeyFiFo->Data[Tail], Input, sizeof (EFI_INPUT_KEY));

EfiKeyFiFo->Tail = (UINT8)((Tail + 1) % (FIFO_MAX_NUMBER + 1));
EfiKeyFiFo->Tail = (UINT16)((Tail + 1) % (FIFO_MAX_NUMBER + 1)); // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

return TRUE;
}
Expand All @@ -855,7 +860,7 @@ EfiKeyFiFoForNotifyRemoveOneKey (
EFI_INPUT_KEY *Output
)
{
UINT8 Head;
UINT16 Head; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

Head = EfiKeyFiFo->Head;
ASSERT (Head < FIFO_MAX_NUMBER + 1);
Expand All @@ -871,7 +876,7 @@ EfiKeyFiFoForNotifyRemoveOneKey (

CopyMem (Output, &EfiKeyFiFo->Data[Head], sizeof (EFI_INPUT_KEY));

EfiKeyFiFo->Head = (UINT8)((Head + 1) % (FIFO_MAX_NUMBER + 1));
EfiKeyFiFo->Head = (UINT16)((Head + 1) % (FIFO_MAX_NUMBER + 1)); // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

return TRUE;
}
Expand Down Expand Up @@ -911,8 +916,8 @@ IsEfiKeyFiFoForNotifyFull (
EFI_KEY_FIFO *EfiKeyFiFo
)
{
UINT8 Tail;
UINT8 Head;
UINT16 Tail; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.
UINT16 Head; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

Tail = EfiKeyFiFo->Tail;
Head = EfiKeyFiFo->Head;
Expand Down Expand Up @@ -941,7 +946,7 @@ EfiKeyFiFoInsertOneKey (
EFI_INPUT_KEY *Key
)
{
UINT8 Tail;
UINT16 Tail; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.
LIST_ENTRY *Link;
LIST_ENTRY *NotifyList;
TERMINAL_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
Expand Down Expand Up @@ -985,7 +990,7 @@ EfiKeyFiFoInsertOneKey (

CopyMem (&TerminalDevice->EfiKeyFiFo->Data[Tail], Key, sizeof (EFI_INPUT_KEY));

TerminalDevice->EfiKeyFiFo->Tail = (UINT8)((Tail + 1) % (FIFO_MAX_NUMBER + 1));
TerminalDevice->EfiKeyFiFo->Tail = (UINT16)((Tail + 1) % (FIFO_MAX_NUMBER + 1)); // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

return TRUE;
}
Expand All @@ -1006,7 +1011,7 @@ EfiKeyFiFoRemoveOneKey (
EFI_INPUT_KEY *Output
)
{
UINT8 Head;
UINT16 Head; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

Head = TerminalDevice->EfiKeyFiFo->Head;
ASSERT (Head < FIFO_MAX_NUMBER + 1);
Expand All @@ -1022,7 +1027,7 @@ EfiKeyFiFoRemoveOneKey (

CopyMem (Output, &TerminalDevice->EfiKeyFiFo->Data[Head], sizeof (EFI_INPUT_KEY));

TerminalDevice->EfiKeyFiFo->Head = (UINT8)((Head + 1) % (FIFO_MAX_NUMBER + 1));
TerminalDevice->EfiKeyFiFo->Head = (UINT16)((Head + 1) % (FIFO_MAX_NUMBER + 1)); // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

return TRUE;
}
Expand Down Expand Up @@ -1062,8 +1067,8 @@ IsEfiKeyFiFoFull (
TERMINAL_DEV *TerminalDevice
)
{
UINT8 Tail;
UINT8 Head;
UINT16 Tail; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.
UINT16 Head; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

Tail = TerminalDevice->EfiKeyFiFo->Tail;
Head = TerminalDevice->EfiKeyFiFo->Head;
Expand Down Expand Up @@ -1092,7 +1097,7 @@ UnicodeFiFoInsertOneKey (
UINT16 Input
)
{
UINT8 Tail;
UINT16 Tail; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

Tail = TerminalDevice->UnicodeFiFo->Tail;
ASSERT (Tail < FIFO_MAX_NUMBER + 1);
Expand All @@ -1106,7 +1111,7 @@ UnicodeFiFoInsertOneKey (

TerminalDevice->UnicodeFiFo->Data[Tail] = Input;

TerminalDevice->UnicodeFiFo->Tail = (UINT8)((Tail + 1) % (FIFO_MAX_NUMBER + 1));
TerminalDevice->UnicodeFiFo->Tail = (UINT16)((Tail + 1) % (FIFO_MAX_NUMBER + 1)); // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

return TRUE;
}
Expand All @@ -1126,14 +1131,14 @@ UnicodeFiFoRemoveOneKey (
UINT16 *Output
)
{
UINT8 Head;
UINT16 Head; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

Head = TerminalDevice->UnicodeFiFo->Head;
ASSERT (Head < FIFO_MAX_NUMBER + 1);

*Output = TerminalDevice->UnicodeFiFo->Data[Head];

TerminalDevice->UnicodeFiFo->Head = (UINT8)((Head + 1) % (FIFO_MAX_NUMBER + 1));
TerminalDevice->UnicodeFiFo->Head = (UINT16)((Head + 1) % (FIFO_MAX_NUMBER + 1)); // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.
}

/**
Expand Down Expand Up @@ -1171,8 +1176,8 @@ IsUnicodeFiFoFull (
TERMINAL_DEV *TerminalDevice
)
{
UINT8 Tail;
UINT8 Head;
UINT16 Tail; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.
UINT16 Head; // MU_CHANGE: Extending the FIFO buffer size beyond UINT8 width.

Tail = TerminalDevice->UnicodeFiFo->Tail;
Head = TerminalDevice->UnicodeFiFo->Head;
Expand Down

0 comments on commit 69909c3

Please sign in to comment.