public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Leif Lindholm <quic_llindhol@quicinc.com>,
	Sami Mujawar <sami.mujawar@arm.com>
Subject: [edk2-devel] [PATCH 2/9] ArmVirtPkg/Fdt16550SerialPortHookLib: rebase to FdtSerialPortAddressLib
Date: Sun,  8 Oct 2023 17:39:05 +0200	[thread overview]
Message-ID: <20231008153912.175941-3-lersek@redhat.com> (raw)
In-Reply-To: <20231008153912.175941-1-lersek@redhat.com>

This is only a refactoring; the patch is not supposed to cause any
observable change.

Build-tested only (with "ArmVirtKvmTool.dsc").

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf |  3 +-
 ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c   | 88 +-------------------
 2 files changed, 4 insertions(+), 87 deletions(-)

diff --git a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf
index 007a45eca2a6..22aba53d9b48 100644
--- a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf
+++ b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf
@@ -22,12 +22,11 @@ [Sources]
 [LibraryClasses]
   BaseLib
   PcdLib
-  FdtLib
+  FdtSerialPortAddressLib
   HobLib
 
 [Packages]
   ArmVirtPkg/ArmVirtPkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
 
diff --git a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c
index c1b81920214b..03d28b9282ea 100644
--- a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c
+++ b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c
@@ -17,90 +17,7 @@
 #include <Library/HobLib.h>
 #include <Library/PcdLib.h>
 #include <Library/PlatformHookLib.h>
-#include <libfdt.h>
-
-/** Get the UART base address of the console serial-port from the DT.
-
-  This function fetches the node referenced in the "stdout-path"
-  property of the "chosen" node and returns the base address of
-  the console UART.
-
-  @param [in]   Fdt                   Pointer to a Flattened Device Tree (Fdt).
-  @param [out]  SerialConsoleAddress  If success, contains the base address
-                                      of the console serial-port.
-
-  @retval EFI_SUCCESS             The function completed successfully.
-  @retval EFI_NOT_FOUND           Console serial-port info not found in DT.
-  @retval EFI_INVALID_PARAMETER   Invalid parameter.
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-GetSerialConsolePortAddress (
-  IN  CONST VOID    *Fdt,
-  OUT       UINT64  *SerialConsoleAddress
-  )
-{
-  CONST CHAR8   *Prop;
-  INT32         PropSize;
-  CONST CHAR8   *Path;
-  INT32         PathLen;
-  INT32         ChosenNode;
-  INT32         SerialConsoleNode;
-  INT32         Len;
-  CONST CHAR8   *NodeStatus;
-  CONST UINT64  *RegProperty;
-
-  if ((Fdt == NULL) || (fdt_check_header (Fdt) != 0)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  // The "chosen" node resides at the root of the DT. Fetch it.
-  ChosenNode = fdt_path_offset (Fdt, "/chosen");
-  if (ChosenNode < 0) {
-    return EFI_NOT_FOUND;
-  }
-
-  Prop = fdt_getprop (Fdt, ChosenNode, "stdout-path", &PropSize);
-  if (PropSize < 0) {
-    return EFI_NOT_FOUND;
-  }
-
-  // Determine the actual path length, as a colon terminates the path.
-  Path = ScanMem8 (Prop, PropSize, ':');
-  if (Path == NULL) {
-    PathLen = AsciiStrLen (Prop);
-  } else {
-    PathLen = Path - Prop;
-  }
-
-  // Aliases cannot start with a '/', so it must be the actual path.
-  if (Prop[0] == '/') {
-    SerialConsoleNode = fdt_path_offset_namelen (Fdt, Prop, PathLen);
-  } else {
-    // Lookup the alias, as this contains the actual path.
-    Path = fdt_get_alias_namelen (Fdt, Prop, PathLen);
-    if (Path == NULL) {
-      return EFI_NOT_FOUND;
-    }
-
-    SerialConsoleNode = fdt_path_offset (Fdt, Path);
-  }
-
-  NodeStatus = fdt_getprop (Fdt, SerialConsoleNode, "status", &Len);
-  if ((NodeStatus != NULL) && (AsciiStrCmp (NodeStatus, "okay") != 0)) {
-    return EFI_NOT_FOUND;
-  }
-
-  RegProperty = fdt_getprop (Fdt, SerialConsoleNode, "reg", &Len);
-  if (Len != 16) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  *SerialConsoleAddress = fdt64_to_cpu (ReadUnaligned64 (RegProperty));
-
-  return EFI_SUCCESS;
-}
+#include <Library/FdtSerialPortAddressLib.h>
 
 /** Platform hook to retrieve the 16550 UART base address from the platform
     Device tree and store it in PcdSerialRegisterBase.
@@ -108,6 +25,7 @@ GetSerialConsolePortAddress (
   @retval RETURN_SUCCESS            Success.
   @retval RETURN_INVALID_PARAMETER  A parameter was invalid.
   @retval RETURN_NOT_FOUND          Serial port information not found.
+  @retval RETURN_PROTOCOL_ERROR     Invalid information in the Device Tree.
 
 **/
 RETURN_STATUS
@@ -129,7 +47,7 @@ PlatformHookSerialPortInitialize (
     return RETURN_NOT_FOUND;
   }
 
-  Status = GetSerialConsolePortAddress (DeviceTreeBase, &SerialConsoleAddress);
+  Status = FdtSerialGetConsolePort (DeviceTreeBase, &SerialConsoleAddress);
   if (RETURN_ERROR (Status)) {
     return Status;
   }



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#109400): https://edk2.groups.io/g/devel/message/109400
Mute This Topic: https://groups.io/mt/101834887/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2023-10-08 15:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-08 15:39 [edk2-devel] [PATCH 0/9] ArmVirtPkg: support two PL011 UARTs Laszlo Ersek
2023-10-08 15:39 ` [edk2-devel] [PATCH 1/9] ArmVirtPkg: introduce FdtSerialPortAddressLib Laszlo Ersek
2023-10-08 15:39 ` Laszlo Ersek [this message]
2023-10-08 15:39 ` [edk2-devel] [PATCH 3/9] ArmVirtPkg: adjust whitespace in block scope declarations Laszlo Ersek
2023-10-08 15:39 ` [edk2-devel] [PATCH 4/9] ArmVirtPkg: adhere to the serial port selected by /chosen "stdout-path" Laszlo Ersek
2023-10-08 15:39 ` [edk2-devel] [PATCH 5/9] ArmVirtPkg: store separate console and debug PL011 addresses in GUID HOB Laszlo Ersek
2023-10-08 15:39 ` [edk2-devel] [PATCH 6/9] ArmVirtPkg: introduce DebugLibFdtPL011Uart Flash instance Laszlo Ersek
2023-10-08 15:39 ` [edk2-devel] [PATCH 7/9] ArmVirtPkg: introduce DebugLibFdtPL011Uart RAM instance Laszlo Ersek
2023-10-08 15:39 ` [edk2-devel] [PATCH 8/9] ArmVirtPkg: introduce DebugLibFdtPL011Uart DXE Runtime instance Laszlo Ersek
2023-10-08 15:39 ` [edk2-devel] [PATCH 9/9] ArmVirtPkg: steer DebugLib output away from SerialPortLib+console traffic Laszlo Ersek
2023-10-10  7:43 ` [edk2-devel] [PATCH 0/9] ArmVirtPkg: support two PL011 UARTs Ard Biesheuvel
2023-10-10 15:33   ` Laszlo Ersek
2023-10-26 14:21     ` Peter Maydell
2023-10-26 14:46       ` Julien Grall
2023-10-26 14:55         ` Ard Biesheuvel
2023-10-26 15:36           ` Laszlo Ersek
2023-10-26 15:30         ` Laszlo Ersek
2023-10-26 15:19       ` Laszlo Ersek
2023-10-26 15:21         ` Ard Biesheuvel
2023-10-26 19:00           ` Laszlo Ersek
2023-10-27 10:57         ` Gerd Hoffmann

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=20231008153912.175941-3-lersek@redhat.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