From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.9395.1588690248644375747 for ; Tue, 05 May 2020 07:50:48 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5452E31B; Tue, 5 May 2020 07:50:48 -0700 (PDT) Received: from e123331-lin.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 054303F68F; Tue, 5 May 2020 07:50:46 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: leif@nuviainc.com, pete@akeo.ie, andrey.warkentin@gmail.com, Ard Biesheuvel Subject: [PATCH edk2-platforms 5/5] Platform/RaspberryPi: create DXE phase SerialPortLib version for RPi3 Date: Tue, 5 May 2020 16:50:29 +0200 Message-Id: <20200505145029.29826-6-ard.biesheuvel@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200505145029.29826-1-ard.biesheuvel@arm.com> References: <20200505145029.29826-1-ard.biesheuvel@arm.com> 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; +} -- 2.17.1