--- /dev/null
+/** @file\r
+ CBMEM console SerialPortLib instance\r
+\r
+ Copyright (c) 2022, Baruch Binyamin Doron\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+#include <Coreboot.h>\r
+\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/BlParseLib.h>\r
+#include <Library/SerialPortLib.h>\r
+\r
+// Upper nibble contains flags\r
+#define CBMC_CURSOR_MASK ((1 << 28) - 1)\r
+#define CBMC_OVERFLOW (1 << 31)\r
+\r
+STATIC struct cbmem_console *mCbConsole = NULL;\r
+\r
+/**\r
+ Find coreboot record with given Tag.\r
+ NOTE: This coreboot-specific function definition is absent\r
+ from the common BlParseLib header.\r
+\r
+ @param Tag The tag id to be found\r
+\r
+ @retval NULL The Tag is not found.\r
+ @retval Others The pointer to the record found.\r
+\r
+**/\r
+VOID *\r
+FindCbTag (\r
+ IN UINT32 Tag\r
+ );\r
+\r
+/**\r
+ Initialize the serial device hardware.\r
+\r
+ If no initialization is required, then return RETURN_SUCCESS.\r
+ If the serial device was successfully initialized, then return RETURN_SUCCESS.\r
+ If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.\r
+\r
+ @retval RETURN_SUCCESS The serial device was initialized.\r
+ @retval RETURN_DEVICE_ERROR The serial device could not be initialized.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortInitialize (\r
+ VOID\r
+ )\r
+{\r
+ struct cb_cbmem_ref *CbMemRef;\r
+\r
+ // The coreboot table contains large structures as references\r
+ CbMemRef = FindCbTag (CB_TAG_CBMEM_CONSOLE);\r
+ if (CbMemRef == NULL) {\r
+ return RETURN_DEVICE_ERROR;\r
+ }\r
+\r
+ mCbConsole = (VOID *)(UINTN)CbMemRef->cbmem_addr; // Support PEI and DXE\r
+ if (mCbConsole == NULL) {\r
+ return RETURN_DEVICE_ERROR;\r
+ }\r
+\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+ Write data from buffer to serial device.\r
+\r
+ Writes NumberOfBytes data bytes from Buffer to the serial device.\r
+ The number of bytes actually written to the serial device is returned.\r
+ If the return value is less than NumberOfBytes, then the write operation failed.\r
+ If Buffer is NULL, then ASSERT().\r
+ If NumberOfBytes is zero, then return 0.\r
+\r
+ @param Buffer Pointer to the data buffer to be written.\r
+ @param NumberOfBytes Number of bytes to written to the serial device.\r
+\r
+ @retval 0 NumberOfBytes is 0.\r
+ @retval >0 The number of bytes written to the serial device.\r
+ If this value is less than NumberOfBytes, then the write operation failed.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+SerialPortWrite (\r
+ IN UINT8 *Buffer,\r
+ IN UINTN NumberOfBytes\r
+ )\r
+{\r
+ UINT32 Cursor;\r
+ UINT32 Flags;\r
+\r
+ if ((Buffer == NULL) || (NumberOfBytes == 0)) {\r
+ return 0;\r
+ }\r
+\r
+ if (mCbConsole == NULL) {\r
+ return 0;\r
+ }\r
+\r
+ Cursor = mCbConsole->cursor & CBMC_CURSOR_MASK;\r
+ Flags = mCbConsole->cursor & ~CBMC_CURSOR_MASK;\r
+ if (Cursor >= mCbConsole->size) {\r
+ // Already overflowed; bail out. TODO: Is this unnecessarily cautious?\r
+ // - Supports old coreboot version with legacy overflow mechanism.\r
+ return 0;\r
+ }\r
+\r
+ if (Cursor + NumberOfBytes > mCbConsole->size) {\r
+ // Will overflow, zero cursor and set flag.\r
+ Cursor = 0;\r
+ Flags |= CBMC_OVERFLOW;\r
+ }\r
+\r
+ if (NumberOfBytes > mCbConsole->size) {\r
+ // This one debug message is longer than the entire buffer. Truncate it.\r
+ // - TODO: Is this unnecessarily cautious?\r
+ NumberOfBytes = mCbConsole->size;\r
+ }\r
+\r
+ CopyMem (&mCbConsole->body[Cursor], Buffer, NumberOfBytes);\r
+ Cursor += NumberOfBytes;\r
+\r
+ if (Cursor == mCbConsole->size) {\r
+ // Next message will overflow, zero cursor.\r
+ // - Set flag preemptively. This could not be determined later.\r
+ Cursor = 0;\r
+ Flags |= CBMC_OVERFLOW;\r
+ }\r
+\r
+ mCbConsole->cursor = Flags | Cursor;\r
+\r
+ return NumberOfBytes;\r
+}\r
+\r
+/**\r
+ Read data from serial device and save the datas in buffer.\r
+\r
+ Reads NumberOfBytes data bytes from a serial device into the buffer\r
+ specified by Buffer. The number of bytes actually read is returned.\r
+ If Buffer is NULL, then ASSERT().\r
+ If NumberOfBytes is zero, then return 0.\r
+\r
+ @param Buffer Pointer to the data buffer to store the data read from the serial device.\r
+ @param NumberOfBytes Number of bytes which will be read.\r
+\r
+ @retval 0 Read data failed, no data is to be read.\r
+ @retval >0 Actual number of bytes read from serial device.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+SerialPortRead (\r
+ OUT UINT8 *Buffer,\r
+ IN UINTN NumberOfBytes\r
+ )\r
+{\r
+ return 0;\r
+}\r
+\r
+/**\r
+ Polls a serial device to see if there is any data waiting to be read.\r
+\r
+ @retval TRUE Data is waiting to be read from the serial device.\r
+ @retval FALSE There is no data waiting to be read from the serial device.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+SerialPortPoll (\r
+ VOID\r
+ )\r
+{\r
+ return FALSE;\r
+}\r
+\r
+/**\r
+ Sets the control bits on a serial device.\r
+\r
+ @param Control Sets the bits of Control that are settable.\r
+\r
+ @retval RETURN_SUCCESS The new control bits were set on the serial device.\r
+ @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortSetControl (\r
+ IN UINT32 Control\r
+ )\r
+{\r
+ return RETURN_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+ Retrieve the status of the control bits on a serial device.\r
+\r
+ @param Control A pointer to return the current control signals from the serial device.\r
+\r
+ @retval RETURN_SUCCESS The control bits were read from the serial device.\r
+ @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortGetControl (\r
+ OUT UINT32 *Control\r
+ )\r
+{\r
+ return RETURN_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+ Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,\r
+ data bits, and stop bits on a serial device.\r
+\r
+ @param BaudRate The requested baud rate. A BaudRate value of 0 will use the\r
+ device's default interface speed.\r
+ On output, the value actually set.\r
+ @param ReceiveFifoDepth The requested depth of the FIFO on the receive side of the\r
+ serial interface. A ReceiveFifoDepth value of 0 will use\r
+ the device's default FIFO depth.\r
+ On output, the value actually set.\r
+ @param Timeout The requested time out for a single character in microseconds.\r
+ This timeout applies to both the transmit and receive side of the\r
+ interface. A Timeout value of 0 will use the device's default time\r
+ out value.\r
+ On output, the value actually set.\r
+ @param Parity The type of parity to use on this serial device. A Parity value of\r
+ DefaultParity will use the device's default parity value.\r
+ On output, the value actually set.\r
+ @param DataBits The number of data bits to use on the serial device. A DataBits\r
+ value of 0 will use the device's default data bit setting.\r
+ On output, the value actually set.\r
+ @param StopBits The number of stop bits to use on this serial device. A StopBits\r
+ value of DefaultStopBits will use the device's default number of\r
+ stop bits.\r
+ On output, the value actually set.\r
+\r
+ @retval RETURN_SUCCESS The new attributes were set on the serial device.\r
+ @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
+ @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.\r
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortSetAttributes (\r
+ IN OUT UINT64 *BaudRate,\r
+ IN OUT UINT32 *ReceiveFifoDepth,\r
+ IN OUT UINT32 *Timeout,\r
+ IN OUT EFI_PARITY_TYPE *Parity,\r
+ IN OUT UINT8 *DataBits,\r
+ IN OUT EFI_STOP_BITS_TYPE *StopBits\r
+ )\r
+{\r
+ return RETURN_UNSUPPORTED;\r
+}\r
DEFINE PS2_MOUSE_ENABLE = TRUE\r
DEFINE CRYPTO_PROTOCOL_SUPPORT = FALSE\r
DEFINE SD_MMC_TIMEOUT = 1000000\r
+ DEFINE USE_CBMEM_FOR_CONSOLE = FALSE\r
\r
#\r
# NULL: NullMemoryTestDxe\r
\r
[BuildOptions]\r
*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES\r
- GCC:*_UNIXGCC_*_CC_FLAGS = -DMDEPKG_NDEBUG\r
+!if $(USE_CBMEM_FOR_CONSOLE) == FALSE\r
GCC:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG\r
INTEL:RELEASE_*_*_CC_FLAGS = /D MDEPKG_NDEBUG\r
MSFT:RELEASE_*_*_CC_FLAGS = /D MDEPKG_NDEBUG\r
+!endif\r
\r
[BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER]\r
GCC:*_*_*_DLINK_FLAGS = -z common-page-size=0x1000\r
TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
!endif\r
ResetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf\r
+!if $(USE_CBMEM_FOR_CONSOLE) == TRUE\r
+ SerialPortLib|UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf\r
+ PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf\r
+!else\r
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf\r
PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf\r
+!endif\r
PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf\r
IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf\r
\r
gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }\r
gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x7\r
gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F\r
-!if $(SOURCE_DEBUG_ENABLE)\r
- gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17\r
+!if $(USE_CBMEM_FOR_CONSOLE) == FALSE\r
+ !if $(SOURCE_DEBUG_ENABLE)\r
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17\r
+ !else\r
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F\r
+ !endif\r
!else\r
- gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F\r
+ !if $(TARGET) == DEBUG\r
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x07\r
+ !else\r
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x03\r
+ !endif\r
!endif\r
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxSizeNonPopulateCapsule|$(MAX_SIZE_NON_POPULATE_CAPSULE)\r
#\r
gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode\r
gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress\r
gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize\r
-!if $(TARGET) == DEBUG\r
+!if ($(TARGET) == DEBUG || $(USE_CBMEM_FOR_CONSOLE) == TRUE)\r
gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|TRUE\r
!else\r
gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|FALSE\r