From nobody Mon Apr 29 11:17:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+58630+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58630+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1588690243; cv=none; d=zohomail.com; s=zohoarc; b=LPlCyGX9ekPkHGkKYRNngy1nPtgeogtxOQZS6lFdozKkzp+T6+RQV7qPPfUexXt004Jty38peKEWLsp/b9gJCgI9ReX0Fm6RvHw+xLmOUWrx86tHUMB0FeGC9EJLM3od1ciAgle4+/e8gCeZSAYVrmNHz25/Nbf/vG2wmD3nFws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588690243; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=+sklfYF2eNLD01Ni4L+w1p5Fcb8AY3qEXKBx8rTnO/U=; b=YgyPEj7tmtOkv95tnBull1bUIqREGxBUNz7C0Xk8yeMPbeDqRGEKn5n/tpmCesogjp/d4atPlr+LQWcZDjGxdmgwN30PO5arPDs8YTLsd06+CVMt1uCu9Hev9jXZWHjYsH4MaDy8gNcarxg5T0aFEtumr4Cxmc6hjDaHRpsX6lQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58630+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1588690243301253.3023460584542; Tue, 5 May 2020 07:50:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id s7Y1YY1788612xIhwA4IZgA3; Tue, 05 May 2020 07:50:42 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.9387.1588690241954806367 for ; Tue, 05 May 2020 07:50:42 -0700 X-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 81D5831B; Tue, 5 May 2020 07:50:41 -0700 (PDT) X-Received: from e123331-lin.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1BBE73F68F; Tue, 5 May 2020 07:50:39 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: leif@nuviainc.com, pete@akeo.ie, andrey.warkentin@gmail.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH edk2-platforms 1/5] Platform/RaspberryPi/DualSerialPortLib: split up to ease reuse Date: Tue, 5 May 2020 16:50:25 +0200 Message-Id: <20200505145029.29826-2-ard.biesheuvel@arm.com> In-Reply-To: <20200505145029.29826-1-ard.biesheuvel@arm.com> References: <20200505145029.29826-1-ard.biesheuvel@arm.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: QHesE0D954YevEtNxFgl5v86x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1588690242; bh=x2pTSZiRa3qs1+oR8aYaNz9Q9oN9oyLFdBUGFB8sQ2g=; h=Cc:Date:From:Reply-To:Subject:To; b=ueZDziF/GlmIbPlw5eJr9eUHN1I1DZJrfiC3QBwLG0jXRuaLY+eW4ps1G5ek9AkQQVG YacnM4s9r0bX7IaIpJB/aH/zdQK09342Qx5osi+lg/xjefb8wjsFOr/XaVUHfx+Y3TN5U lWW4Ixu9vRlcXVGSPI9U8JCsmDGvlGkU9ck= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In preparation of creating different versions of DualSerialPortLib, split off the parts that will be shared between all versions. Signed-off-by: Ard Biesheuvel Reviewed-by: Pete Batard --- Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.inf |= 5 +- Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.h |= 82 +++++++ Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c |= 229 +------------------- Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLibCommon.c |= 218 +++++++++++++++++++ 4 files changed, 305 insertions(+), 229 deletions(-) diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortL= ib.inf b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.i= nf index af1e6b026fe6..fda9ff2bcbf9 100644 --- a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.inf +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.inf @@ -19,9 +19,8 @@ [Defines] =20 [Packages] ArmPlatformPkg/ArmPlatformPkg.dec - EmbeddedPkg/EmbeddedPkg.dec - MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec Silicon/Broadcom/Bcm283x/Bcm283x.dec =20 [LibraryClasses] @@ -32,6 +31,8 @@ [LibraryClasses] =20 [Sources] DualSerialPortLib.c + DualSerialPortLib.h + DualSerialPortLibCommon.c =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterAccessWidth ## SOMET= IMES_CONSUMES diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortL= ib.h b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.h new file mode 100644 index 000000000000..a8d150f516b9 --- /dev/null +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.h @@ -0,0 +1,82 @@ +/** @file + 16550 and PL011 Serial Port library functions for Raspberry Pi + + Copyright (c) 2020, Pete Batard + Copyright (c) 2018, AMD Incorporated. All rights reserved.
+ Copyright (c) 2014, Hewlett-Packard Development Company, L.P.
+ Copyright (c) 2012 - 2016, ARM Ltd. All rights reserved.
+ Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +#define PL011_UART_REGISTER_BASE BCM2836_PL011_UART_BASE_ADDRESS +#define MINI_UART_REGISTER_BASE (BCM2836_MINI_UART_BASE_ADDRESS + 0x= 40) + +// +// 16550 UART register offsets and bitfields +// +#define R_UART_RXBUF 0 // LCR_DLAB =3D 0 +#define R_UART_TXBUF 0 // LCR_DLAB =3D 0 +#define R_UART_BAUD_LOW 0 // LCR_DLAB =3D 1 +#define R_UART_BAUD_HIGH 1 // LCR_DLAB =3D 1 +#define R_UART_IER 1 // LCR_DLAB =3D 0 +#define R_UART_FCR 2 +#define B_UART_FCR_FIFOE BIT0 +#define B_UART_FCR_FIFO64 BIT5 +#define R_UART_LCR 3 +#define B_UART_LCR_DLAB BIT7 +#define R_UART_MCR 4 +#define B_UART_MCR_DTRC BIT0 +#define B_UART_MCR_RTS BIT1 +#define R_UART_LSR 5 +#define B_UART_LSR_RXRDY BIT0 +#define B_UART_LSR_TXRDY BIT5 +#define B_UART_LSR_TEMT BIT6 +#define R_UART_MSR 6 +#define B_UART_MSR_CTS BIT4 +#define B_UART_MSR_DSR BIT5 +#define B_UART_MSR_RI BIT6 +#define B_UART_MSR_DCD BIT7 + +extern BOOLEAN UsePl011Uart; +extern BOOLEAN UsePl011UartSet; + +/** + Read an 8-bit 16550 register. + + @param Base The base address register of UART device. + @param Offset The offset of the 16550 register to read. + + @return The value read from the 16550 register. + +**/ +UINT8 +SerialPortReadRegister ( + UINTN Base, + UINTN Offset + ); + +/** + Write an 8-bit 16550 register. + + @param Base The base address register of UART device. + @param Offset The offset of the 16550 register to write. + @param Value The value to write to the 16550 register specified by Of= fset. + + @return The value written to the 16550 register. + +**/ +UINT8 +SerialPortWriteRegister ( + UINTN Base, + UINTN Offset, + UINT8 Value + ); + diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortL= ib.c b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c index 05e12f383785..b1d17d3fa04a 100644 --- a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c @@ -13,132 +13,13 @@ **/ =20 #include -#include -#include -#include #include #include #include #include #include =20 -BOOLEAN UsePl011Uart =3D FALSE; -BOOLEAN UsePl011UartSet =3D FALSE; - -#define PL011_UART_REGISTER_BASE BCM2836_PL011_UART_BASE_ADDRESS -#define MINI_UART_REGISTER_BASE (BCM2836_MINI_UART_BASE_ADDRESS + 0x= 40) - -// -// 16550 UART register offsets and bitfields -// -#define R_UART_RXBUF 0 // LCR_DLAB =3D 0 -#define R_UART_TXBUF 0 // LCR_DLAB =3D 0 -#define R_UART_BAUD_LOW 0 // LCR_DLAB =3D 1 -#define R_UART_BAUD_HIGH 1 // LCR_DLAB =3D 1 -#define R_UART_IER 1 // LCR_DLAB =3D 0 -#define R_UART_FCR 2 -#define B_UART_FCR_FIFOE BIT0 -#define B_UART_FCR_FIFO64 BIT5 -#define R_UART_LCR 3 -#define B_UART_LCR_DLAB BIT7 -#define R_UART_MCR 4 -#define B_UART_MCR_DTRC BIT0 -#define B_UART_MCR_RTS BIT1 -#define R_UART_LSR 5 -#define B_UART_LSR_RXRDY BIT0 -#define B_UART_LSR_TXRDY BIT5 -#define B_UART_LSR_TEMT BIT6 -#define R_UART_MSR 6 -#define B_UART_MSR_CTS BIT4 -#define B_UART_MSR_DSR BIT5 -#define B_UART_MSR_RI BIT6 -#define B_UART_MSR_DCD BIT7 - -/** - Read an 8-bit 16550 register. - - @param Base The base address register of UART device. - @param Offset The offset of the 16550 register to read. - - @return The value read from the 16550 register. - -**/ -UINT8 -SerialPortReadRegister ( - UINTN Base, - UINTN Offset - ) -{ - return MmioRead8 (Base + Offset * PcdGet32 (PcdSerialRegisterStride)); -} - -/** - Write an 8-bit 16550 register. - - @param Base The base address register of UART device. - @param Offset The offset of the 16550 register to write. - @param Value The value to write to the 16550 register specified by Of= fset. - - @return The value written to the 16550 register. - -**/ -UINT8 -SerialPortWriteRegister ( - UINTN Base, - UINTN Offset, - UINT8 Value - ) -{ - return MmioWrite8 (Base + Offset * PcdGet32 (PcdSerialRegisterStride), V= alue); -} - -/** - Return whether the hardware flow control signal allows writing. - - @param SerialRegisterBase The base address register of UART device. - - @retval TRUE The serial port is writable. - @retval FALSE The serial port is not writable. -**/ -BOOLEAN -SerialPortWritable ( - UINTN SerialRegisterBase - ) -{ - if (PcdGetBool (PcdSerialUseHardwareFlowControl)) { - if (PcdGetBool (PcdSerialDetectCable)) { - // - // Wait for both DSR and CTS to be set - // DSR is set if a cable is connected. - // CTS is set if it is ok to transmit data - // - // DSR CTS Description Action - // =3D=3D=3D =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D - // 0 0 No cable connected. Wait - // 0 1 No cable connected. Wait - // 1 0 Cable connected, but not clear to send. Wait - // 1 1 Cable connected, and clear to send. Transmit - // - return (BOOLEAN) ((SerialPortReadRegister (SerialRegisterBase, R_UAR= T_MSR) & (B_UART_MSR_DSR | B_UART_MSR_CTS)) =3D=3D (B_UART_MSR_DSR | B_UART= _MSR_CTS)); - } else { - // - // Wait for both DSR and CTS to be set OR for DSR to be clear. - // DSR is set if a cable is connected. - // CTS is set if it is ok to transmit data - // - // DSR CTS Description Action - // =3D=3D=3D =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D - // 0 0 No cable connected. Transmit - // 0 1 No cable connected. Transmit - // 1 0 Cable connected, but not clear to send. Wait - // 1 1 Cable connected, and clar to send. Transmit - // - return (BOOLEAN) ((SerialPortReadRegister (SerialRegisterBase, R_UAR= T_MSR) & (B_UART_MSR_DSR | B_UART_MSR_CTS)) !=3D (B_UART_MSR_DSR)); - } - } - - return TRUE; -} +#include "DualSerialPortLib.h" =20 /** Return the baud generator divisor to use for 16650 setup. @@ -147,6 +28,7 @@ SerialPortWritable ( =20 @return The baud generator divisor. **/ +STATIC UINT32 SerialPortGetDivisor ( UINT32 SerialBaudRate @@ -288,113 +170,6 @@ SerialPortInitialize ( } } =20 -/** - Write data from buffer to serial device. - - Writes NumberOfBytes data bytes from Buffer to the serial device. - The number of bytes actually written to the serial device is returned. - If the return value is less than NumberOfBytes, then the write operation= failed. - - If Buffer is NULL, then ASSERT(). - - If NumberOfBytes is zero, then return 0. - - @param Buffer Pointer to the data buffer to be written. - @param NumberOfBytes Number of bytes to written to the serial device. - - @retval 0 NumberOfBytes is 0. - @retval >0 The number of bytes written to the serial devic= e. - If this value is less than NumberOfBytes, then = the write operation failed. - -**/ -UINTN -EFIAPI -SerialPortWrite ( - IN UINT8 *Buffer, - IN UINTN NumberOfBytes - ) -{ - UINTN SerialRegisterBase; - UINTN Result; - UINTN Index; - UINTN FifoSize; - - // - // Serial writes may happen *before* the UART has been initialized - // and if we use the wrong UART then, all kind of bad things happen. - // To alleviate this, we add UART detection in SerialPortWrite and - // guard the UART detection with a second boolean. - // - if (!UsePl011UartSet) { - UsePl011Uart =3D ((MmioRead32(GPIO_BASE_ADDRESS + 4) & 0x0003F000) =3D= =3D 0x00024000); - UsePl011UartSet =3D TRUE; - } - - if (UsePl011Uart) { - return PL011UartWrite (PL011_UART_REGISTER_BASE, Buffer, NumberOfBytes= ); - } else { - if (Buffer =3D=3D NULL) { - return 0; - } - - SerialRegisterBase =3D MINI_UART_REGISTER_BASE; - - if (NumberOfBytes =3D=3D 0) { - // - // Flush the hardware - // - - // - // Wait for both the transmit FIFO and shift register empty. - // - while ((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (B= _UART_LSR_TEMT | B_UART_LSR_TXRDY)) !=3D (B_UART_LSR_TEMT | B_UART_LSR_TXRD= Y)); - - // - // Wait for the hardware flow control signal - // - while (!SerialPortWritable (SerialRegisterBase)); - return 0; - } - - // - // Compute the maximum size of the Tx FIFO - // - FifoSize =3D 1; - if ((PcdGet8 (PcdSerialFifoControl) & B_UART_FCR_FIFOE) !=3D 0) { - if ((PcdGet8 (PcdSerialFifoControl) & B_UART_FCR_FIFO64) =3D=3D 0) { - FifoSize =3D 16; - } else { - FifoSize =3D PcdGet32 (PcdSerialExtendedTxFifoSize); - } - } - - Result =3D NumberOfBytes; - while (NumberOfBytes !=3D 0) { - // - // Wait for the serial port to be ready, to make sure both the trans= mit FIFO - // and shift register empty. - // - while ((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (B= _UART_LSR_TEMT | B_UART_LSR_TXRDY)) !=3D (B_UART_LSR_TEMT | B_UART_LSR_TXRD= Y)); - - // - // Fill then entire Tx FIFO - // - for (Index =3D 0; Index < FifoSize && NumberOfBytes !=3D 0; Index++,= NumberOfBytes--, Buffer++) { - // - // Wait for the hardware flow control signal - // - while (!SerialPortWritable (SerialRegisterBase)); - - // - // Write byte to the transmit buffer. - // - SerialPortWriteRegister (SerialRegisterBase, R_UART_TXBUF, *Buffer= ); - } - } - return Result; - } -} - /** Reads data from a serial device into a buffer. =20 diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortL= ibCommon.c b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortL= ibCommon.c new file mode 100644 index 000000000000..48d8df280640 --- /dev/null +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLibCommo= n.c @@ -0,0 +1,218 @@ +/** @file + 16550 and PL011 Serial Port library functions for Raspberry Pi + + Copyright (c) 2020, Pete Batard + Copyright (c) 2018, AMD Incorporated. All rights reserved.
+ Copyright (c) 2014, Hewlett-Packard Development Company, L.P.
+ Copyright (c) 2012 - 2016, ARM Ltd. All rights reserved.
+ Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +#include "DualSerialPortLib.h" + +BOOLEAN UsePl011Uart =3D FALSE; +BOOLEAN UsePl011UartSet =3D FALSE; + +/** + Read an 8-bit 16550 register. + + @param Base The base address register of UART device. + @param Offset The offset of the 16550 register to read. + + @return The value read from the 16550 register. + +**/ +UINT8 +SerialPortReadRegister ( + UINTN Base, + UINTN Offset + ) +{ + return MmioRead8 (Base + Offset * PcdGet32 (PcdSerialRegisterStride)); +} + +/** + Write an 8-bit 16550 register. + + @param Base The base address register of UART device. + @param Offset The offset of the 16550 register to write. + @param Value The value to write to the 16550 register specified by Of= fset. + + @return The value written to the 16550 register. + +**/ +UINT8 +SerialPortWriteRegister ( + UINTN Base, + UINTN Offset, + UINT8 Value + ) +{ + return MmioWrite8 (Base + Offset * PcdGet32 (PcdSerialRegisterStride), V= alue); +} + +/** + Return whether the hardware flow control signal allows writing. + + @param SerialRegisterBase The base address register of UART device. + + @retval TRUE The serial port is writable. + @retval FALSE The serial port is not writable. +**/ +STATIC +BOOLEAN +SerialPortWritable ( + UINTN SerialRegisterBase + ) +{ + if (PcdGetBool (PcdSerialUseHardwareFlowControl)) { + if (PcdGetBool (PcdSerialDetectCable)) { + // + // Wait for both DSR and CTS to be set + // DSR is set if a cable is connected. + // CTS is set if it is ok to transmit data + // + // DSR CTS Description Action + // =3D=3D=3D =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D + // 0 0 No cable connected. Wait + // 0 1 No cable connected. Wait + // 1 0 Cable connected, but not clear to send. Wait + // 1 1 Cable connected, and clear to send. Transmit + // + return (BOOLEAN) ((SerialPortReadRegister (SerialRegisterBase, R_UAR= T_MSR) & (B_UART_MSR_DSR | B_UART_MSR_CTS)) =3D=3D (B_UART_MSR_DSR | B_UART= _MSR_CTS)); + } else { + // + // Wait for both DSR and CTS to be set OR for DSR to be clear. + // DSR is set if a cable is connected. + // CTS is set if it is ok to transmit data + // + // DSR CTS Description Action + // =3D=3D=3D =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D + // 0 0 No cable connected. Transmit + // 0 1 No cable connected. Transmit + // 1 0 Cable connected, but not clear to send. Wait + // 1 1 Cable connected, and clar to send. Transmit + // + return (BOOLEAN) ((SerialPortReadRegister (SerialRegisterBase, R_UAR= T_MSR) & (B_UART_MSR_DSR | B_UART_MSR_CTS)) !=3D (B_UART_MSR_DSR)); + } + } + + return TRUE; +} + +/** + Write data from buffer to serial device. + + Writes NumberOfBytes data bytes from Buffer to the serial device. + The number of bytes actually written to the serial device is returned. + If the return value is less than NumberOfBytes, then the write operation= failed. + + If Buffer is NULL, then ASSERT(). + + If NumberOfBytes is zero, then return 0. + + @param Buffer Pointer to the data buffer to be written. + @param NumberOfBytes Number of bytes to written to the serial device. + + @retval 0 NumberOfBytes is 0. + @retval >0 The number of bytes written to the serial devic= e. + If this value is less than NumberOfBytes, then = the write operation failed. + +**/ +UINTN +EFIAPI +SerialPortWrite ( + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + UINTN SerialRegisterBase; + UINTN Result; + UINTN Index; + UINTN FifoSize; + + // + // Serial writes may happen *before* the UART has been initialized + // and if we use the wrong UART then, all kind of bad things happen. + // To alleviate this, we add UART detection in SerialPortWrite and + // guard the UART detection with a second boolean. + // + if (!UsePl011UartSet) { + UsePl011Uart =3D ((MmioRead32(GPIO_BASE_ADDRESS + 4) & 0x0003F000) =3D= =3D 0x00024000); + UsePl011UartSet =3D TRUE; + } + + if (UsePl011Uart) { + return PL011UartWrite (PL011_UART_REGISTER_BASE, Buffer, NumberOfBytes= ); + } else { + if (Buffer =3D=3D NULL) { + return 0; + } + + SerialRegisterBase =3D MINI_UART_REGISTER_BASE; + + if (NumberOfBytes =3D=3D 0) { + // + // Flush the hardware + // + + // + // Wait for both the transmit FIFO and shift register empty. + // + while ((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (B= _UART_LSR_TEMT | B_UART_LSR_TXRDY)) !=3D (B_UART_LSR_TEMT | B_UART_LSR_TXRD= Y)); + + // + // Wait for the hardware flow control signal + // + while (!SerialPortWritable (SerialRegisterBase)); + return 0; + } + + // + // Compute the maximum size of the Tx FIFO + // + FifoSize =3D 1; + if ((PcdGet8 (PcdSerialFifoControl) & B_UART_FCR_FIFOE) !=3D 0) { + if ((PcdGet8 (PcdSerialFifoControl) & B_UART_FCR_FIFO64) =3D=3D 0) { + FifoSize =3D 16; + } else { + FifoSize =3D PcdGet32 (PcdSerialExtendedTxFifoSize); + } + } + + Result =3D NumberOfBytes; + while (NumberOfBytes !=3D 0) { + // + // Wait for the serial port to be ready, to make sure both the trans= mit FIFO + // and shift register empty. + // + while ((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (B= _UART_LSR_TEMT | B_UART_LSR_TXRDY)) !=3D (B_UART_LSR_TEMT | B_UART_LSR_TXRD= Y)); + + // + // Fill then entire Tx FIFO + // + for (Index =3D 0; Index < FifoSize && NumberOfBytes !=3D 0; Index++,= NumberOfBytes--, Buffer++) { + // + // Wait for the hardware flow control signal + // + while (!SerialPortWritable (SerialRegisterBase)); + + // + // Write byte to the transmit buffer. + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_TXBUF, *Buffer= ); + } + } + return Result; + } +} --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58630): https://edk2.groups.io/g/devel/message/58630 Mute This Topic: https://groups.io/mt/73999453/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:17:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+58631+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58631+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1588690245; cv=none; d=zohomail.com; s=zohoarc; b=Hz1n3rjun3jjP6o0J/139+VAM/jW/wBe3A2LVqXMSl1GgSMmn8WMx/fC+ZoNpu8UJAsvFH3zrlCKgGS38ifz+8KCAfljeoUKwtYVW9M6MNq62X3mWr/0bxIrJXmK/Y/TdnF3bdoeTn1H5HCCKq47/HrQIjC6xdNh0NhDi0yOvvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588690245; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=Xrp5aNqEcCxixH0Dh575xMDELZAH4kYjI17295QpZBc=; b=LBeyqAPFB1YYrpEm8VYEH5sPK2rck4/8nyM9Hch/xCi+nzWAJgnOP48LqQ+Jq2Kbuoljzc39IyzMFzXJMI6sNY9vyNledYMphFyWyx+iPjjz1g5xGoRkuCK3aK3orGqY6J7lOdfczooY5orZnG1nG3llEHiz/QNGs7I4LIwttzI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58631+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 158869024582392.65668852802833; Tue, 5 May 2020 07:50:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id gRI0YY1788612xKUK9kByJNj; Tue, 05 May 2020 07:50:45 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.9394.1588690244676783998 for ; Tue, 05 May 2020 07:50:44 -0700 X-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 3CF841FB; Tue, 5 May 2020 07:50:43 -0700 (PDT) X-Received: from e123331-lin.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CD4563F68F; Tue, 5 May 2020 07:50:41 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: leif@nuviainc.com, pete@akeo.ie, andrey.warkentin@gmail.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH edk2-platforms 2/5] Platform/RaspberryPi: introduce DebugDualSerialPortLib Date: Tue, 5 May 2020 16:50:26 +0200 Message-Id: <20200505145029.29826-3-ard.biesheuvel@arm.com> In-Reply-To: <20200505145029.29826-1-ard.biesheuvel@arm.com> References: <20200505145029.29826-1-ard.biesheuvel@arm.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: BkXyXVX3yOfdLDhDm0k2yIFZx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1588690245; bh=wxGRJqQwMD3RV71Twyu0zM81O4e2OtekzPP3cRbylvA=; h=Cc:Date:From:Reply-To:Subject:To; b=aMO0/ELuardEn6pi3IE/Vmlflgc0WBYOpC9jFl2CViKv/Je/sGqVuVzWLCH332fid6g IKj4uyZv1D77m4a6NUjvnOkRXA8dQrTEoUg1x5b6J5Z/VqT9qni9JBNvGtIbvyyJgP12J RHrrK0KsTJaS2izTuxq5WxkBzaUZcg37FB8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" On DEBUG builds that use the serial port directly for debug output, every module reinitializes the UART hardware, through the DebugLib constructor calling SerialPortInitialize. This is unnecessary, but usually harmless. However, in cases where this requires information that is non-trivial to obtain (e.g., the rate of the clock source feeding the baud clock), it results in a special kind of dependency hell that can only be fully appreciated by seasoned EDK2 connoisseurs [0]. As a first step towards solving this mess, implement a special version of the Raspberry Pi dual serial port library that only implements the SerialPortInitialize() and SerialPortWrite() library functions, and make the former an empty stub. This makes it only suitable for use by modules that inherit a dependency on SerialPortLib via DebugLib, and requires us to ensure that the baud clock is programmed correctly by the SEC phase. Use this version of the library to satisfy all SerialPortLib dependencies except the ones in PrePi and in SerialDxe. These will retain the full version, which is the only one that still consumes PcdSerialClockRate. [0] There are two distinct problems making this mess almost unsolvable: - SerialPortInitialize() is called directly in various places instead of relying on constructor ordering, so adding a constructor to a SerialPortLib implementation does not help, - Constructor ordering resolution in the EDK2 tooling fails to take transitive dependencies into account if an intermediate library has no constructor it self. For instance, if LibA depends on LibB, which depends on LibC, the constructors of LibA and LibC could be called in any order if LibB does not have a constructor itself (and fixing this breaks all the platforms in the tree) Signed-off-by: Ard Biesheuvel Reviewed-by: Pete Batard --- Platform/RaspberryPi/RPi3/RPi3.dsc = | 12 +++-- Platform/RaspberryPi/RPi4/RPi4.dsc = | 12 +++-- Platform/RaspberryPi/Library/DualSerialPortLib/DebugDualSerialPortLib.inf = | 46 ++++++++++++++++++++ Platform/RaspberryPi/Library/DualSerialPortLib/DebugDualSerialPortLib.c = | 28 ++++++++++++ 4 files changed, 92 insertions(+), 6 deletions(-) diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3= /RPi3.dsc index 563fb891b841..d7218219fc5a 100644 --- a/Platform/RaspberryPi/RPi3/RPi3.dsc +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc @@ -127,7 +127,7 @@ [LibraryClasses.common] # Dual serial port library PL011UartClockLib|ArmPlatformPkg/Library/PL011UartClockLib/PL011UartCloc= kLib.inf PL011UartLib|ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.inf - SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialP= ortLib.inf + SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DebugDualSe= rialPortLib.inf =20 # Cryptographic libraries IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf @@ -521,7 +521,10 @@ [Components.common] # # PEI Phase modules # - ArmPlatformPkg/PrePi/PeiUniCore.inf + ArmPlatformPkg/PrePi/PeiUniCore.inf { + + SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSer= ialPortLib.inf + } =20 # # DXE @@ -569,7 +572,10 @@ [Components.common] MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf - MdeModulePkg/Universal/SerialDxe/SerialDxe.inf + MdeModulePkg/Universal/SerialDxe/SerialDxe.inf { + + SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSer= ialPortLib.inf + } Platform/RaspberryPi/Drivers/DisplayDxe/DisplayDxe.inf =20 MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc index 4deccd9d3ecc..4fb015b077e6 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -127,7 +127,7 @@ [LibraryClasses.common] # Dual serial port library PL011UartClockLib|ArmPlatformPkg/Library/PL011UartClockLib/PL011UartCloc= kLib.inf PL011UartLib|ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.inf - SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialP= ortLib.inf + SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DebugDualSe= rialPortLib.inf =20 # Cryptographic libraries IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf @@ -536,7 +536,10 @@ [Components.common] # # PEI Phase modules # - ArmPlatformPkg/PrePi/PeiUniCore.inf + ArmPlatformPkg/PrePi/PeiUniCore.inf { + + SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSer= ialPortLib.inf + } =20 # # DXE @@ -584,7 +587,10 @@ [Components.common] MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf - MdeModulePkg/Universal/SerialDxe/SerialDxe.inf + MdeModulePkg/Universal/SerialDxe/SerialDxe.inf { + + SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSer= ialPortLib.inf + } Platform/RaspberryPi/Drivers/DisplayDxe/DisplayDxe.inf EmbeddedPkg/Drivers/ConsolePrefDxe/ConsolePrefDxe.inf =20 diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DebugDualSerial= PortLib.inf b/Platform/RaspberryPi/Library/DualSerialPortLib/DebugDualSeria= lPortLib.inf new file mode 100644 index 000000000000..cd14d44c59d8 --- /dev/null +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DebugDualSerialPortLib= .inf @@ -0,0 +1,46 @@ +## @file +# +# SerialPortLib instance for both PL011 and 16550 UART that satisfies +# only the dependencies of DebugLib. +# +# Copyright (c) 2020, Pete Batard +# Copyright (c) 2012 - 2020, ARM Ltd. All rights reserved.
+# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D DebugDualSerialPortLib + FILE_GUID =3D 323bae1b-c2fc-4929-a2fe-9e9174f8ce0f + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SerialPortLib + +[Packages] + ArmPlatformPkg/ArmPlatformPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Broadcom/Bcm283x/Bcm283x.dec + +[LibraryClasses] + IoLib + PcdLib + PL011UartLib + +[Sources] + DebugDualSerialPortLib.c + DualSerialPortLib.h + DualSerialPortLibCommon.c + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSU= MES + +[FixedPcd] + gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress ## CONSU= MES diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DebugDualSerial= PortLib.c b/Platform/RaspberryPi/Library/DualSerialPortLib/DebugDualSerialP= ortLib.c new file mode 100644 index 000000000000..fbb9fde08bac --- /dev/null +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DebugDualSerialPortLib= .c @@ -0,0 +1,28 @@ +/** @file + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +/** + Initialize the serial device hardware. + + If no initialization is required, then return RETURN_SUCCESS. + If the serial device was successfully initialized, then return RETURN_SU= CCESS. + If the serial device could not be initialized, then return RETURN_DEVICE= _ERROR. + + @retval RETURN_SUCCESS The serial device was initialized. + @retval RETURN_DEVICE_ERROR The serial device could not be initialized. + +**/ +RETURN_STATUS +EFIAPI +SerialPortInitialize ( + VOID + ) +{ + return RETURN_SUCCESS; +} --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58631): https://edk2.groups.io/g/devel/message/58631 Mute This Topic: https://groups.io/mt/73999455/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:17:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+58632+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58632+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1588690246; cv=none; d=zohomail.com; s=zohoarc; b=haxtdm6R5CnR0EiKkkuNv+Knr0vzhHCvxej2iNNH5oi/FHrU1oUP3IdLvQ5fYQ7loTeMfSr/Ef4rObGMP1H8+SuR/pfjG/FGi+DnbDRIh2AqCxOX44QhE+C2h4ulR6eruj27EDfrPMWUoQPwiUHMRcRFeK7bebMyAS5E5LOCLbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588690246; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=+ytFnYkAK1ZOwNaWVE7Ss4qxCmwA7YAvB/QXNe6vv/k=; b=A9zWq2ti1/TBHYXRopN74knNh2Srff41JbvaS4okaEhmnAe8wvVd5coYVGeh/RHiMZ7kkRNwQEHxclcYAuE/JET3zEqJq8OauZXfkXkGjjr/pb/plDVxK7txpuRxN4lKRmOErnQJXZuxLwJRbaiy6zMSu/Rhn3Liy1VzHcIxv60= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58632+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1588690246389550.4176930389494; Tue, 5 May 2020 07:50:46 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id jPzuYY1788612xhg0ddZYKXY; Tue, 05 May 2020 07:50:46 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.9304.1588690245331963720 for ; Tue, 05 May 2020 07:50:45 -0700 X-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 F287631B; Tue, 5 May 2020 07:50:44 -0700 (PDT) X-Received: from e123331-lin.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 831483F68F; Tue, 5 May 2020 07:50:43 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: leif@nuviainc.com, pete@akeo.ie, andrey.warkentin@gmail.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH edk2-platforms 3/5] Platform/RaspberryPi: fix 16550 divisor calculation logic Date: Tue, 5 May 2020 16:50:27 +0200 Message-Id: <20200505145029.29826-4-ard.biesheuvel@arm.com> In-Reply-To: <20200505145029.29826-1-ard.biesheuvel@arm.com> References: <20200505145029.29826-1-ard.biesheuvel@arm.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: Wc6XgPnxMDXxBy4YChQPrkDMx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1588690246; bh=LzcoFDaqR9UGHXhRV2AM89AXrgtnzVAE3JhNlFNn1mg=; h=Cc:Date:From:Reply-To:Subject:To; b=SIkYMMfVD1O3lghdGIpOw1mRasQecNj06vrkuHDIqmRjGNvLtz4NdF89SnpzEGhpAll FzJmUVzI3e047iINmO+AoAZMZxc1wRj2o77fZ4twlnMf82tLn3zVFFt+h4ZlgwkJOAT5t AZj++ZaA3hiqTlfXe7zBQuOeP+RmKrr05+0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The 16550 'miniUART' on the Raspberry Pi gets its input clock from different sources on RPi3 and RPi3. Fix the logic that derives the divisor for the 16550 baud clock on the respective platforms. While at it, make the input clock PCD patchable for RPi3 so we can manipulate it at runtime in a future patch. Co-authored-by: Pete Batard Co-authored-by: Andrei Warkentin Co-authored-by: Ard Biesheuvel Signed-off-by: Pete Batard Signed-off-by: Ard Biesheuvel Reviewed-by: Pete Batard --- Platform/RaspberryPi/RPi3/RPi3.dsc | 4 ++= +- Platform/RaspberryPi/RPi4/RPi4.dsc | 2 +- Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c | 14 ++= ++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3= /RPi3.dsc index d7218219fc5a..96b27400eef8 100644 --- a/Platform/RaspberryPi/RPi3/RPi3.dsc +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc @@ -409,7 +409,6 @@ [PcdsFixedAtBuild.common] gArmPlatformTokenSpaceGuid.PL011UartClkInHz|48000000 gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride|4 - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|500000000 gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl|0x27 gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize|8 gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200 @@ -441,6 +440,9 @@ [PcdsFixedAtBuild.common] gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor|L"EDK2" gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|TRUE =20 +[PcdsPatchableInModule] + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|250000000 + [PcdsDynamicHii.common.DEFAULT] =20 # diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc index 4fb015b077e6..5d8bd88d7e34 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -420,7 +420,7 @@ [PcdsFixedAtBuild.common] gArmPlatformTokenSpaceGuid.PL011UartClkInHz|48000000 gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride|4 - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|500000000 + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|1000000000 gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl|0x27 gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize|8 gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200 diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortL= ib.c b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c index b1d17d3fa04a..5e83bbf022eb 100644 --- a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c @@ -41,18 +41,20 @@ SerialPortGetDivisor ( // On the Raspberry Pi, the clock to use for the 16650-compatible UART // is the base clock divided by the 12.12 fixed point VPU clock divisor. // - BaseClockRate =3D (UINT64)PcdGet32 (PcdSerialClockRate) * 4; + BaseClockRate =3D (UINT64)PcdGet32 (PcdSerialClockRate); +#if (RPI_MODEL =3D=3D 4) Divisor =3D MmioRead32(BCM2836_CM_BASE + BCM2836_CM_VPU_CLOCK_DIVISOR) &= 0xFFFFFF; if (Divisor !=3D 0) BaseClockRate =3D (BaseClockRate << 12) / Divisor; +#endif =20 // - // Now calculate divisor for baud generator - // Ref_Clk_Rate / Baud_Rate / 16 + // As per the BCM2xxx datasheets: + // baudrate =3D system_clock_freq / (8 * (divisor + 1)). // - Divisor =3D (UINT32)BaseClockRate / (SerialBaudRate * 16); - if (((UINT32)BaseClockRate % (SerialBaudRate * 16)) >=3D SerialBaudRate = * 8) { - Divisor++; + Divisor =3D (UINT32)BaseClockRate / (SerialBaudRate * 8); + if (Divisor !=3D 0) { + Divisor--; } return Divisor; } --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58632): https://edk2.groups.io/g/devel/message/58632 Mute This Topic: https://groups.io/mt/73999456/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:17:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+58633+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58633+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1588690248; cv=none; d=zohomail.com; s=zohoarc; b=b1/mZSP9m2CruDCe0lohAq32A8lePXJGVq5eGySpg2k3WJFonOlCihRDFihlBw2/dfRohs5EqLqNRpZj0WGFDTsPHjZoJq4SoIE9Sp0rPluP69J/hK7lnpp7xXBP9xP/KI9lW/Dm2nIC9srZBladS4e6QJmAoO+OIkaJbZuVUZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588690248; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=qpH4oB6ZstoGpASY9Cf56JZwrtKzlNCJfRIybKW2kYM=; b=KMXaK8l5flZY8JfETVPHJQ9lkPDjsEuFw2qdNJ2F6zgfdT3K9TJcNNELZDydPVzAxPBnktqU8GrAdVZJhpmS06PsOttafY5zkOgXtfISNJlcJ3+FZHHoQe3xwOusGpQHHHXFLwYuRvJkrY1xgJH7aRnDd7rxZ8VitO0hergNAss= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58633+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1588690248130787.2054912200604; Tue, 5 May 2020 07:50:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aR0TYY1788612xOUUOpRNINd; Tue, 05 May 2020 07:50:47 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.9393.1588690246979666646 for ; Tue, 05 May 2020 07:50:47 -0700 X-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 A12911FB; Tue, 5 May 2020 07:50:46 -0700 (PDT) X-Received: from e123331-lin.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5CB0A3F68F; Tue, 5 May 2020 07:50:45 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: leif@nuviainc.com, pete@akeo.ie, andrey.warkentin@gmail.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH edk2-platforms 4/5] Platform/RaspberryPi3: query firmware for 16550 input clock at boot Date: Tue, 5 May 2020 16:50:28 +0200 Message-Id: <20200505145029.29826-5-ard.biesheuvel@arm.com> In-Reply-To: <20200505145029.29826-1-ard.biesheuvel@arm.com> References: <20200505145029.29826-1-ard.biesheuvel@arm.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: WFTYtQY0VRNKzCdM5kRghLUJx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1588690247; bh=O5N0uxS9tm6KA6p9UPDE1rxXRq1Lkv2PDm9Di4UZFck=; h=Cc:Date:From:Reply-To:Subject:To; b=BmsjzUJ9ta4uIF3+J+XmTvc+U3qdhaCwjQC7nWXGwqN2ZKtV21NlL0lgMUVRTX49/ja 5n+hMUWy6R0EX9nqycQWao7H9MPZGsBcBWMsP80P/uElZLafgVDLNKbi2rHg+UPZsYBXw vq8kR3TOca1wnDQ/x76Qw8T08q9B3MOkm8g= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Query the firmware for the clock rate that is used to drive the 16550 baud clock, so that we can program the correct baud rate. Co-authored-by: Pete Batard Co-authored-by: Andrei Warkentin Co-authored-by: Ard Biesheuvel Signed-off-by: Pete Batard Signed-off-by: Ard Biesheuvel Reviewed-by: Pete Batard --- Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S | 25 = +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHe= lper.S b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper= .S index 91dfe1bb981e..35580e4ed73a 100644 --- a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S +++ b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S @@ -3,7 +3,7 @@ * Copyright (c) 2020, Andrei Warkentin * Copyright (c) 2019-2020, Pete Batard * Copyright (c) 2016, Linaro Limited. All rights reserved. - * Copyright (c) 2011-2013, ARM Limited. All rights reserved. + * Copyright (c) 2011-2020, ARM Limited. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent * @@ -85,6 +85,14 @@ ASM_FUNC (ArmPlatformPeiBootAction) adr x2, mBoardRevision str w0, [x2] =20 +#if (RPI_MODEL =3D=3D 3) + run .Lclkinfo_buffer + + ldr w0, .Lfrequency + adrp x2, _gPcd_BinaryPatch_PcdSerialClockRate + str w0, [x2, :lo12:_gPcd_BinaryPatch_PcdSerialClockRate] +#endif + ret =20 .align 4 @@ -127,6 +135,21 @@ ASM_FUNC (ArmPlatformPeiBootAction) .long 0 // end tag .set .Lrevinfo_size, . - .Lrevinfo_buffer =20 +#if (RPI_MODEL =3D=3D 3) + .align 4 +.Lclkinfo_buffer: + .long .Lclkinfo_size + .long 0x0 + .long RPI_MBOX_GET_CLOCK_RATE + .long 8 // buf size + .long 4 // input len + .long 4 // clock id: 0x04 =3D Core/VPU +.Lfrequency: + .long 0 // frequency + .long 0 // end tag + .set .Lclkinfo_size, . - .Lclkinfo_buffer +#endif + //UINTN //ArmPlatformGetPrimaryCoreMpId ( // VOID --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58633): https://edk2.groups.io/g/devel/message/58633 Mute This Topic: https://groups.io/mt/73999457/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:17:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+58634+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58634+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1588690249; cv=none; d=zohomail.com; s=zohoarc; b=CFVqtDPkQUv6ttHVHRXJPg/t1g9ZHyFderLc+MsyGcFJqloQ4IT25lQ45mwkFaSW7+cUNkGnHPNbV9tpLHU9VzEv5myL1i1Wn8/KLnq895N/NJoGVrC9sLKkaVdiIBuEGKxVOTCFv04DHNECYqZPM1p2sGcPDEK8lQvrv+Jhdds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588690249; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=Pr6BIeBsZLiOR9SqmQs5xQzsFECc16Bwdkxp2NW6gkA=; b=C4W2zXgj948GGpimSeDVMEBawxfYYeoRMLBVDE4LYG+o26jE6qr8yJnpKHJHzQjWQAiRE77ZDrlsnUlR2wbdI5py0r0/Zh5WZebt5opy/HiTF5/75NpK3jDXJX6HvKyM6prccEFR3aYV+nvt2kqVml1bua9WZzo6GdosLsRSL98= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58634+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1588690249522682.5811445254228; Tue, 5 May 2020 07:50:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qE1xYY1788612xM08PAZOISJ; Tue, 05 May 2020 07:50:49 -0700 X-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 X-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) X-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: [edk2-devel] [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> In-Reply-To: <20200505145029.29826-1-ard.biesheuvel@arm.com> References: <20200505145029.29826-1-ard.biesheuvel@arm.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: HhapiixCrpK27zVMV4eel8F4x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1588690249; bh=jX/YGVvBAfnVTVa9Li4ViMqR0NAysCYQEj5J/0EkPW0=; h=Cc:Date:From:Reply-To:Subject:To; b=BYaoqgXoFaoeWKEdpOxIPvfuz0WyyF3WUHL4mPcp+027RNsdJXe3B6ySpWf82+TDtWg ace8MQVjfUPx5/X+v85i2P++Uc1d2TyzougNUEIND5P2C8mFg9fNDl++oNpI8PZIfAcpt egI9kJiHU0L+eolzMswjtn9kvHXM09p/arA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Pete Batard Tested-by: Pete Batard --- Platform/RaspberryPi/RPi3/RPi3.dsc = | 2 +- Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortDxeLib.inf = | 67 ++++++++++++++++++++ Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLibConstructo= r.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/DualSer= ialPortLib.inf + SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSer= ialPortDxeLib.inf } Platform/RaspberryPi/Drivers/DisplayDxe/DisplayDxe.inf =20 diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortD= xeLib.inf b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortDx= eLib.inf new file mode 100644 index 000000000000..4c22b39daa7f --- /dev/null +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortDxeLib.i= nf @@ -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 =3D 1.27 + BASE_NAME =3D DualSerialPortDxeLib + FILE_GUID =3D d586667e-ec50-4bf6-9701-fb4e29055a60 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SerialPortLib|DXE_DRIVER + CONSTRUCTOR =3D 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 ## SOMET= IMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable ## SOMET= IMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialPciDeviceInfo ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSU= MES + +[FixedPcd] + gArmPlatformTokenSpaceGuid.PL011UartClkInHz + gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits + +[Protocols] + gRaspberryPiFirmwareProtocolGuid ## CONSU= MES + +[PatchPcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate ## CONSU= MES + +[Depex] + gRaspberryPiFirmwareProtocolGuid diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortL= ibConstructor.c b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerial= PortLibConstructor.c new file mode 100644 index 000000000000..c6d695181ab7 --- /dev/null +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLibConst= ructor.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 =3D SystemTable->BootServices->LocateProtocol ( + &gRaspberryPiFirmwareProtocolGuid, + NULL, (VOID **)&Firmware); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D Firmware->GetClockRate (RPI_MBOX_CLOCK_RATE_CORE, &ClockRate); + if (EFI_ERROR (Status)) { + return Status; + } + + PatchPcdSet32 (PcdSerialClockRate, ClockRate); + return EFI_SUCCESS; +} --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58634): https://edk2.groups.io/g/devel/message/58634 Mute This Topic: https://groups.io/mt/73999459/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-