public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Abdul Lateef Attar" <abdattar@amd.com>
To: <devel@edk2.groups.io>
Cc: Abdul Lateef Attar <abdattar@amd.com>, Abner Chang <abner.chang@amd.com>
Subject: [PATCH v1 1/1] AMD/AmdMinBoardPkg: Implements SpcrDeviceLib library
Date: Mon, 8 May 2023 12:33:17 +0530	[thread overview]
Message-ID: <e6bac3438862e6018ce772cf34d4618f8b1bcbca.1683529243.git.abdattar@amd.com> (raw)
In-Reply-To: <cover.1683529243.git.abdattar@amd.com>

Implements SpcrDeviceLib library for AMD common boards.

Cc: Abner Chang <abner.chang@amd.com>
Signed-off-by: Abdul Lateef Attar <abdattar@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


  reply	other threads:[~2023-05-08  7:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08  7:03 [PATCH v1 0/1] AMD/AmdMinBoardPkg: Implements SpcrDeviceLib library Abdul Lateef Attar
2023-05-08  7:03 ` Abdul Lateef Attar [this message]
2023-05-09  6:41 ` Chang, Abner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e6bac3438862e6018ce772cf34d4618f8b1bcbca.1683529243.git.abdattar@amd.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox