diff --git a/UefiPayloadPkg/Library/System76EcLib/System76EcLib.c b/UefiPayloadPkg/Library/System76EcLib/System76EcLib.c new file mode 100644 index 0000000000..9bb7a90606 --- /dev/null +++ b/UefiPayloadPkg/Library/System76EcLib/System76EcLib.c @@ -0,0 +1,144 @@ +/** @file + System76 EC logging + + Copyright (c) 2020 System76, Inc. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +// From coreboot/src/drivers/system76_ec/system76_ec.c { +#define SYSTEM76_EC_BASE 0x0E00 + +static inline UINT8 system76_ec_read(UINT8 addr) { + return IoRead8(SYSTEM76_EC_BASE + (UINT16)addr); +} + +static inline void system76_ec_write(UINT8 addr, UINT8 data) { + IoWrite8(SYSTEM76_EC_BASE + (UINT16)addr, data); +} + +void system76_ec_init(void) { + // Clear entire command region + for (int i = 0; i < 256; i++) { + system76_ec_write((UINT8)i, 0); + } +} + +void system76_ec_flush(void) { + // Send command + system76_ec_write(0, 4); + + // Wait for command completion + while (system76_ec_read(0) != 0) {} + + // Clear length + system76_ec_write(3, 0); +} + +void system76_ec_print(UINT8 byte) { + // Read length + UINT8 len = system76_ec_read(3); + // Write data at offset + system76_ec_write(len + 4, byte); + // Update length + system76_ec_write(3, len + 1); + + // If we hit the end of the buffer, or were given a newline, flush + if (byte == '\n' || len >= 128) { + system76_ec_flush(); + } +} +// } From coreboot/src/drivers/system76_ec/system76_ec.c + +// Implement SerialPortLib { +#include + +RETURN_STATUS +EFIAPI +SerialPortInitialize ( + VOID + ) +{ + system76_ec_init(); + return RETURN_SUCCESS; +} + +UINTN +EFIAPI +SerialPortWrite ( + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + if (Buffer == NULL) { + return 0; + } + + if (NumberOfBytes == 0) { + system76_ec_flush(); + return 0; + } + + for(UINTN i = 0; i < NumberOfBytes; i++) { + system76_ec_print(Buffer[i]); + } + + return NumberOfBytes; +} + +BOOLEAN +EFIAPI +SerialPortPoll ( + VOID + ) +{ + return FALSE; +} + +RETURN_STATUS +EFIAPI +SerialPortGetControl ( + OUT UINT32 *Control + ) +{ + return RETURN_UNSUPPORTED; +} + +RETURN_STATUS +EFIAPI +SerialPortSetControl ( + IN UINT32 Control + ) +{ + return RETURN_UNSUPPORTED; +} + +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 + ) +{ + return RETURN_UNSUPPORTED; +} +// } Implement SerialPortLib + +// Implement PlatformHookLib { +#include + +RETURN_STATUS +EFIAPI +PlatformHookSerialPortInitialize ( + VOID + ) +{ + return RETURN_SUCCESS; +} +// } Implement PlatformHookLib diff --git a/UefiPayloadPkg/Library/System76EcLib/System76EcLib.inf b/UefiPayloadPkg/Library/System76EcLib/System76EcLib.inf new file mode 100644 index 0000000000..e82206f63b --- /dev/null +++ b/UefiPayloadPkg/Library/System76EcLib/System76EcLib.inf @@ -0,0 +1,28 @@ +## @file +# System76 EC logging. +# +# Copyright (c) 2020, System76, Inc. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = System76EcLib + MODULE_UNI_FILE = System76EcLib.uni + FILE_GUID = 76ECF0DD-148B-4E48-8589-FC998823F8C2 + MODULE_TYPE = BASE + VERSION_STRING = 0.1 + LIBRARY_CLASS = System76EcLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiPayloadPkg/UefiPayloadPkg.dec + +[LibraryClasses] + IoLib + +[Sources] + System76EcLib.c + +[Pcd] diff --git a/UefiPayloadPkg/Library/System76EcLib/System76EcLib.uni b/UefiPayloadPkg/Library/System76EcLib/System76EcLib.uni new file mode 100644 index 0000000000..f0db62f232 --- /dev/null +++ b/UefiPayloadPkg/Library/System76EcLib/System76EcLib.uni @@ -0,0 +1,13 @@ +// /** @file +// System76 EC logging. +// +// Copyright (c) 2020, System76, Inc. +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "System76 EC logging" + +#string STR_MODULE_DESCRIPTION #language en-US "System76 EC logging." + diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index 5fa546eb76..bb4510d2b8 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -32,6 +32,11 @@ DEFINE PLATFORM_BOOT_TIMEOUT = 2 + # + # Send logs to System76 EC + # + DEFINE SYSTEM76_EC_LOGGING = FALSE + # # SBL: UEFI payload for Slim Bootloader # COREBOOT: UEFI payload for coreboot @@ -220,11 +225,16 @@ # TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf ResetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf - SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf -!if $(UNIVERSAL_PAYLOAD) == TRUE - PlatformHookLib|UefiPayloadPkg/Library/UniversalPayloadPlatformHookLib/PlatformHookLib.inf +!if $(SYSTEM76_EC_LOGGING) == TRUE + SerialPortLib|UefiPayloadPkg/Library/System76EcLib/System76EcLib.inf + PlatformHookLib|UefiPayloadPkg/Library/System76EcLib/System76EcLib.inf !else - PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf + SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf + !if $(UNIVERSAL_PAYLOAD) == TRUE + PlatformHookLib|UefiPayloadPkg/Library/UniversalPayloadPlatformHookLib/PlatformHookLib.inf + !else + PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf + !endif !endif PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf