Implements SpcrDeviceLib library for AMD common boards. Cc: Abner Chang <abner.ch...@amd.com> Signed-off-by: Abdul Lateef Attar <abdat...@amd.com> --- .../AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc | 6 ++ .../Library/SpcrDeviceLib/SpcrDeviceLib.inf | 23 +++++ .../Library/SpcrDeviceLib/SpcrDeviceLib.c | 84 +++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100755 Platform/AMD/AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.inf create mode 100755 Platform/AMD/AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.c
diff --git a/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc b/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc index 2f17db5df5fb..273cd74f7842 100644 --- a/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc +++ b/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc @@ -22,9 +22,15 @@ [Packages] MinPlatformPkg/MinPlatformPkg.dec UefiCpuPkg/UefiCpuPkg.dec +[LibraryClasses] + SpcrDeviceLib|AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.inf + [LibraryClasses.common.PEIM] SetCacheMtrrLib|AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.inf +[Components] + AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.inf + [Components.IA32] AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.inf diff --git a/Platform/AMD/AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.inf b/Platform/AMD/AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.inf new file mode 100755 index 000000000000..d9b77e586aa8 --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.inf @@ -0,0 +1,23 @@ +## @file +# Implementation for SpcrDeviceLib Library. +# SpcrDeviceLib is usd for Serial Port Console Redirection Table (SPCR) device. +# +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 1.29 + BASE_NAME = SpcrDeviceLib + FILE_GUID = 9232A55A-45E3-424A-94C6-615AF63C9A6B + VERSION_STRING = 1.0 + MODULE_TYPE = BASE + LIBRARY_CLASS = SpcrDeviceLib + +[Packages] + MdePkg/MdePkg.dec + +[Sources] + SpcrDeviceLib.c diff --git a/Platform/AMD/AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.c b/Platform/AMD/AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.c new file mode 100755 index 000000000000..0762f16fb360 --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.c @@ -0,0 +1,84 @@ +/** @file + +Implements SpcrDeviceLib library functions. +This library implementation is for AMD processor based platforms. + +Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR> + +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Include/Uefi.h> +#include <Protocol/DevicePath.h> +#include <Library/UefiLib.h> +#include <Library/DevicePathLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/MemoryAllocationLib.h> + +STATIC EFI_GUID TerminalTypeGuid[] = { + DEVICE_PATH_MESSAGING_PC_ANSI, + DEVICE_PATH_MESSAGING_VT_100, + DEVICE_PATH_MESSAGING_VT_100_PLUS, + DEVICE_PATH_MESSAGING_VT_UTF8 +}; + +/** + Get a Serial Port device for SPCR. + + @retval NULL Fails to get the DevicePath + DevicePath If success + +**/ +EFI_DEVICE_PATH_PROTOCOL * +EFIAPI +GetSpcrDevice ( + VOID + ) +{ + EFI_DEVICE_PATH_PROTOCOL *VarConsole; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; + VENDOR_DEVICE_PATH *Vendor; + UINTN Size; + BOOLEAN Found; + UINTN Index; + + // look for supported terminal type GUID in the device path + if (GetEfiGlobalVariable2 (L"ConOut", (VOID **)&VarConsole, NULL) == EFI_SUCCESS) { + do { + // Get the Single Device Path + DevicePath = GetNextDevicePathInstance (&VarConsole, &Size); + if (DevicePath == NULL) { + return NULL; + } + + TmpDevicePath = DevicePath; + Found = FALSE; + while (!IsDevicePathEnd (TmpDevicePath)) { + // search for terminal type + Vendor = (VENDOR_DEVICE_PATH *)TmpDevicePath; + for (Index = 0; Index < (sizeof (TerminalTypeGuid) / sizeof (TerminalTypeGuid[0])); Index++) { + if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[Index])) { + Found = TRUE; + break; + } + } + + if (Found) { + break; + } + + TmpDevicePath = NextDevicePathNode (TmpDevicePath); + } + + if (Found) { + return (DevicePath); + } + + FreePool (DevicePath); + } while (VarConsole != NULL); + } + + return NULL; +} -- 2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104254): https://edk2.groups.io/g/devel/message/104254 Mute This Topic: https://groups.io/mt/98756417/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-