From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by mx.groups.io with SMTP id smtpd.web10.3468.1588760358068341304 for ; Wed, 06 May 2020 03:19:18 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=zPDxK7YW; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.128.65, mailfrom: pete@akeo.ie) Received: by mail-wm1-f65.google.com with SMTP id 188so1955624wmc.2 for ; Wed, 06 May 2020 03:19:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=VNNBTeLO+Z+bkaNCyh0Yf9yBzwuaFye3nWt3wahYPPc=; b=zPDxK7YWj0eoQ8u7w7Az22H1s3zPSVZ93euT3B65+4Wjq2LRMKHVhnaS4Bn30FdxHa slFUpbeRkMEzSk/ZiDizjaZlS/6UD6S5CfpEx6vFKmdrFGScryd70iB0ShX2Wf/uFEvf KmZaZXBZ6hnaT37UnJgdS89Ng0tCkXknZCe4qjF3OKk4B9o0Jdq7qKoRZrLnMzd5KnzZ ziL9K8lzzRQ/x4sdIeqnygoao1SXP89Kk9MLSw1iFOh0JtrCgdnj/Rx8DJT8xtKv8C5h gXsXW612TJx6QzF/CjVsRyAtyshA+zCi7SSD0R9F0dzWlgBShkRVeQEQNG4XbqKz98rF liiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=VNNBTeLO+Z+bkaNCyh0Yf9yBzwuaFye3nWt3wahYPPc=; b=icMwUtzSKv+n00l6olSxYmLcWXrwwCUO7uypJnfQVd1zGPYZCXFdJbsDZ30RxSaQiH uih/8IOjEN69cViA3HQiAZwC0aB4Z7pUio0bfOW/AJI7lrEDqdZP6QaUm8WCOATTcOLL f0Tc8eNe6YtG5gs4j2veXMDxdU7VG/wo4C7XrYv59uD13XdbOHSBSlRPgmOEGGKCO7lh I9gytwa1DYA4UwCuMMUH/12Op3Fc12evHSEk9qPj08BL/nlJ2Nyk39l7rFD5u10yHCO2 RLkOe4AeuDi9kTE+p2+kGdJ1XYG//b6HX2VFu9m7jf/seGOIftMhwC2X/cC0gQtGcR3Y MW2g== X-Gm-Message-State: AGi0PuYMYOWiggsfP5YIhS8eXnhs2BsMAg0eAzXa31rpDidvMf0UwYBr ZWe6qBKJlWe3v9lJayRiqtOvzw== X-Google-Smtp-Source: APiQypIMHeqBLNHhLDPTnXgRDsVLEmtkPtBp4WQnsGg+7azmO29//GhqMvdSYA8tbxD9b+ODcI2JdA== X-Received: by 2002:a1c:7d90:: with SMTP id y138mr3863648wmc.121.1588760356599; Wed, 06 May 2020 03:19:16 -0700 (PDT) Return-Path: Received: from [10.0.0.122] ([84.203.75.87]) by smtp.googlemail.com with ESMTPSA id r20sm2198637wmh.26.2020.05.06.03.19.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 May 2020 03:19:16 -0700 (PDT) Subject: Re: [PATCH edk2-platforms 5/5] Platform/RaspberryPi: create DXE phase SerialPortLib version for RPi3 To: Ard Biesheuvel , devel@edk2.groups.io Cc: leif@nuviainc.com, andrey.warkentin@gmail.com References: <20200505145029.29826-1-ard.biesheuvel@arm.com> <20200505145029.29826-6-ard.biesheuvel@arm.com> From: "Pete Batard" Message-ID: <0f6bec02-d85e-b9c1-2acc-257cb4c363ad@akeo.ie> Date: Wed, 6 May 2020 11:19:15 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200505145029.29826-6-ard.biesheuvel@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit 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 > --- > 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 { > > - 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 > +# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
> +# > +# 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.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include > +#include > +#include > + > +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 For the series: Tested-by: Pete Batard Tested-on-platforms: RPi3 Model B+, RPi4 Model B