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.biesheu...@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 <p...@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 <p...@akeo.ie>
For the series:
Tested-by: Pete Batard <p...@akeo.ie>
Tested-on-platforms: RPi3 Model B+, RPi4 Model B
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#58694): https://edk2.groups.io/g/devel/message/58694
Mute This Topic: https://groups.io/mt/73999459/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-