Skip to content

Commit

Permalink
ArmVirtPkg/Fdt16550SerialPortHookLib: rebase to FdtSerialPortAddressLib
Browse files Browse the repository at this point in the history
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>
Message-Id: <20231008153912.175941-3-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=4577
[lersek@redhat.com: add TianoCore BZ reference]
  • Loading branch information
lersek authored and mergify[bot] committed Oct 26, 2023
1 parent eb83b53 commit f078a6f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,97 +17,15 @@
#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.
@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
Expand All @@ -129,7 +47,7 @@ PlatformHookSerialPortInitialize (
return RETURN_NOT_FOUND;
}

Status = GetSerialConsolePortAddress (DeviceTreeBase, &SerialConsoleAddress);
Status = FdtSerialGetConsolePort (DeviceTreeBase, &SerialConsoleAddress);
if (RETURN_ERROR (Status)) {
return Status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
[LibraryClasses]
BaseLib
PcdLib
FdtLib
FdtSerialPortAddressLib
HobLib

[Packages]
ArmVirtPkg/ArmVirtPkg.dec
EmbeddedPkg/EmbeddedPkg.dec
MdeModulePkg/MdeModulePkg.dec
MdePkg/MdePkg.dec

Expand Down

0 comments on commit f078a6f

Please sign in to comment.