From: "Pete Batard" <pete@akeo.ie>
To: Ard Biesheuvel <ard.biesheuvel@arm.com>, devel@edk2.groups.io
Cc: leif@nuviainc.com, andrey.warkentin@gmail.com
Subject: Re: [PATCH edk2-platforms 5/5] Platform/RaspberryPi: create DXE phase SerialPortLib version for RPi3
Date: Wed, 6 May 2020 11:19:15 +0100 [thread overview]
Message-ID: <0f6bec02-d85e-b9c1-2acc-257cb4c363ad@akeo.ie> (raw)
In-Reply-To: <20200505145029.29826-6-ard.biesheuvel@arm.com>
On 2020.05.05 15:50, Ard Biesheuvel wrote:
> The Raspberry Pi 3 derives its 16550 baud clock from the variable core
> clock, and so any reprogramming of the baud rate needs to take the
> actual core clock value into account.
>
> Introduce a DXE phase version of DualSerialPortLib that discovers this
> value in its constructor, using the RPi firmware protocol, and wire it
> up for the RPi3 platform.
>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
> ---
> Platform/RaspberryPi/RPi3/RPi3.dsc | 2 +-
> Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortDxeLib.inf | 67 ++++++++++++++++++++
> Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLibConstructor.c | 40 ++++++++++++
> 3 files changed, 108 insertions(+), 1 deletion(-)
>
> diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc
> index 96b27400eef8..2b8ad1c4bdbd 100644
> --- a/Platform/RaspberryPi/RPi3/RPi3.dsc
> +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
> @@ -576,7 +576,7 @@ [Components.common]
> MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
> MdeModulePkg/Universal/SerialDxe/SerialDxe.inf {
> <LibraryClasses>
> - SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.inf
> + SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortDxeLib.inf
> }
> Platform/RaspberryPi/Drivers/DisplayDxe/DisplayDxe.inf
>
> diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortDxeLib.inf b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortDxeLib.inf
> new file mode 100644
> index 000000000000..4c22b39daa7f
> --- /dev/null
> +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortDxeLib.inf
> @@ -0,0 +1,67 @@
> +## @file
> +#
> +# DXE phase SerialPortLib instance for both PL011 and 16550 UART.
> +#
> +# Copyright (c) 2020, Pete Batard <pete@akeo.ie>
> +# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> + INF_VERSION = 1.27
> + BASE_NAME = DualSerialPortDxeLib
> + FILE_GUID = d586667e-ec50-4bf6-9701-fb4e29055a60
> + MODULE_TYPE = DXE_DRIVER
> + VERSION_STRING = 1.0
> + LIBRARY_CLASS = SerialPortLib|DXE_DRIVER
> + CONSTRUCTOR = DualSerialPortDxeLibConstructor
> +
> +[Packages]
> + ArmPlatformPkg/ArmPlatformPkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> + MdePkg/MdePkg.dec
> + Platform/RaspberryPi/RaspberryPi.dec
> + Silicon/Broadcom/Bcm283x/Bcm283x.dec
> +
> +[LibraryClasses]
> + IoLib
> + PcdLib
> + PL011UartClockLib
> + PL011UartLib
> +
> +[Sources]
> + DualSerialPortLib.c
> + DualSerialPortLib.h
> + DualSerialPortLibCommon.c
> + DualSerialPortLibConstructor.c
> +
> +[Pcd]
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterAccessWidth ## SOMETIMES_CONSUMES
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSUMES
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl ## CONSUMES
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable ## SOMETIMES_CONSUMES
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate ## CONSUMES
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl ## CONSUMES
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl ## CONSUMES
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialPciDeviceInfo ## CONSUMES
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize ## CONSUMES
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSUMES
> +
> +[FixedPcd]
> + gArmPlatformTokenSpaceGuid.PL011UartClkInHz
> + gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
> + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits
> + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity
> + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits
> +
> +[Protocols]
> + gRaspberryPiFirmwareProtocolGuid ## CONSUMES
> +
> +[PatchPcd]
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate ## CONSUMES
> +
> +[Depex]
> + gRaspberryPiFirmwareProtocolGuid
> diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLibConstructor.c b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLibConstructor.c
> new file mode 100644
> index 000000000000..c6d695181ab7
> --- /dev/null
> +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLibConstructor.c
> @@ -0,0 +1,40 @@
> +/** @file
> +
> + Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Uefi.h>
> +#include <IndustryStandard/RpiMbox.h>
> +#include <Library/SerialPortLib.h>
> +#include <Library/PcdLib.h>
> +#include <Protocol/RpiFirmware.h>
> +
> +EFI_STATUS
> +EFIAPI
> +DualSerialPortDxeLibConstructor (
> + IN EFI_HANDLE ImageHandle,
> + IN EFI_SYSTEM_TABLE *SystemTable
> + )
> +{
> + RASPBERRY_PI_FIRMWARE_PROTOCOL *Firmware;
> + UINT32 ClockRate;
> + EFI_STATUS Status;
> +
> + Status = SystemTable->BootServices->LocateProtocol (
> + &gRaspberryPiFirmwareProtocolGuid,
> + NULL, (VOID **)&Firmware);
> + if (EFI_ERROR (Status)) {
> + return Status;
> + }
> +
> + Status = Firmware->GetClockRate (RPI_MBOX_CLOCK_RATE_CORE, &ClockRate);
> + if (EFI_ERROR (Status)) {
> + return Status;
> + }
> +
> + PatchPcdSet32 (PcdSerialClockRate, ClockRate);
> + return EFI_SUCCESS;
> +}
>
Reviewed-by: Pete Batard <pete@akeo.ie>
For the series:
Tested-by: Pete Batard <pete@akeo.ie>
Tested-on-platforms: RPi3 Model B+, RPi4 Model B
next prev parent reply other threads:[~2020-05-06 10:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-05 14:50 [PATCH edk2-platforms 0/5] Platform/RaspberryPi: fix serialportlib dependency hell Ard Biesheuvel
2020-05-05 14:50 ` [PATCH edk2-platforms 1/5] Platform/RaspberryPi/DualSerialPortLib: split up to ease reuse Ard Biesheuvel
2020-05-06 10:18 ` Pete Batard
2020-05-05 14:50 ` [PATCH edk2-platforms 2/5] Platform/RaspberryPi: introduce DebugDualSerialPortLib Ard Biesheuvel
2020-05-06 10:18 ` Pete Batard
2020-05-05 14:50 ` [PATCH edk2-platforms 3/5] Platform/RaspberryPi: fix 16550 divisor calculation logic Ard Biesheuvel
2020-05-05 18:10 ` Ard Biesheuvel
2020-05-06 10:18 ` [edk2-devel] " Pete Batard
2020-05-06 10:25 ` Ard Biesheuvel
2020-05-05 14:50 ` [PATCH edk2-platforms 4/5] Platform/RaspberryPi3: query firmware for 16550 input clock at boot Ard Biesheuvel
2020-05-05 18:11 ` Ard Biesheuvel
2020-05-06 10:18 ` [edk2-devel] " Pete Batard
2020-05-06 10:31 ` Ard Biesheuvel
2020-05-06 10:38 ` Pete Batard
2020-05-05 14:50 ` [PATCH edk2-platforms 5/5] Platform/RaspberryPi: create DXE phase SerialPortLib version for RPi3 Ard Biesheuvel
2020-05-06 10:19 ` Pete Batard [this message]
2020-05-06 16:16 ` [PATCH edk2-platforms 0/5] Platform/RaspberryPi: fix serialportlib dependency hell Ard Biesheuvel
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=0f6bec02-d85e-b9c1-2acc-257cb4c363ad@akeo.ie \
--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