From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by mx.groups.io with SMTP id smtpd.web10.27609.1617435399596280441 for ; Sat, 03 Apr 2021 00:36:39 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Zbd0g879; spf=pass (domain: kernel.org, ip: 198.145.29.99, mailfrom: ardb@kernel.org) Received: by mail.kernel.org (Postfix) with ESMTPSA id 1762F6120F for ; Sat, 3 Apr 2021 07:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617435397; bh=DrJ12bsXsR2ZTVyklZXaiEtAFdgN5vS/YaG930K28vw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Zbd0g8791oFJ+qG31yCx7pwoC8ZkcsCEEvdZ7IC/vNM+3h4nBHcNKF2mBh/NMx0y/ INY1FZy0v1XMGCFX0ITC4JkLPO3UBz0U7+ThY9BXaehlTy9DU1EuJf64CTKUI++6Bu D9jm0ONB3y6jKIYUh8BpfLygyNgJJa+bXbPWBH+3HhN4eIGBN3yWYC4U9dr843oOFi 0e6I/aUXVPqw6g5pp3f4QOZcxmOLLMeLpFUqJ7U6lew3q5Yfm/rsYGFw82dYb56agi UOR2swr815Vy8Wb9o9QPRKj8Qcti/3naSH1zWkjX07dzThek2cL0okWJabnvyzdBvu W1KVxs57+elOw== Received: by mail-oi1-f171.google.com with SMTP id x2so6952001oiv.2 for ; Sat, 03 Apr 2021 00:36:37 -0700 (PDT) X-Gm-Message-State: AOAM530Qe9Iyfh6UExiF9mqiJkRpuHQSIZbSipTXsAHdSEW6Rb47fg41 JrlOjlEgjkqKtizN9ALz39FiZpl8VkQ7mkxmKFg= X-Google-Smtp-Source: ABdhPJw1QC/sqrOga7DwqGf6Qb9W1XMBLvgF/+fT3hl48h/PGWj6ividwC1OOChT1nB6d/2d2V257i4tKsE1s57Mt0g= X-Received: by 2002:aca:7c4:: with SMTP id 187mr12196874oih.47.1617435396408; Sat, 03 Apr 2021 00:36:36 -0700 (PDT) MIME-Version: 1.0 References: <20210402175148.1485-1-mariobalanica02@gmail.com> In-Reply-To: <20210402175148.1485-1-mariobalanica02@gmail.com> From: "Ard Biesheuvel" Date: Sat, 3 Apr 2021 09:36:25 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-platforms][PATCH 1/1] Platform/RaspberryPi: Fix mini UART baud divisor calculation To: =?UTF-8?B?TWFyaW8gQsSDbMSDbmljxIM=?= Cc: devel@edk2.groups.io, Ard Biesheuvel , Leif Lindholm , Peter Batard Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 2 Apr 2021 at 19:52, Mario B=C4=83l=C4=83nic=C4=83 wrote: > > The baud rate divisor calculation for mini UART on BCM2711 is the same > as on older models since this commit: > https://github.com/raspberrypi/firmware/commit/1e5456a > > Signed-off-by: Mario B=C4=83l=C4=83nic=C4=83 Doesn't this make the new build incompatible with the old firmware? Is there a way to support both? > --- > Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c | 1= 5 +++------------ > Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S | = 4 ---- > Platform/RaspberryPi/RPi4/RPi4.dsc | = 6 ++++-- > 3 files changed, 7 insertions(+), 18 deletions(-) > > diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPor= tLib.c b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c > index 5e83bbf022eb..d2f983bf0a9f 100644 > --- a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c > +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c > @@ -34,25 +34,16 @@ SerialPortGetDivisor ( > UINT32 SerialBaudRate > ) > { > - UINT64 BaseClockRate; > + UINT32 BaseClockRate; > UINT32 Divisor; > > - // > - // 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 diviso= r. > - // > - 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 > + BaseClockRate =3D PcdGet32 (PcdSerialClockRate); > > // > // As per the BCM2xxx datasheets: > // baudrate =3D system_clock_freq / (8 * (divisor + 1)). > // > - Divisor =3D (UINT32)BaseClockRate / (SerialBaudRate * 8); > + Divisor =3D BaseClockRate / (SerialBaudRate * 8); > if (Divisor !=3D 0) { > Divisor--; > } > diff --git a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPi= Helper.S b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelp= er.S > index 58351e4fb8cc..7008aaf8aa4c 100644 > --- a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.= S > +++ b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.= S > @@ -85,13 +85,11 @@ ASM_FUNC (ArmPlatformPeiBootAction) > adr x2, mBoardRevision > str w0, [x2] > > -#if (RPI_MODEL =3D=3D 3) > run .Lclkinfo_buffer > > ldr w0, .Lfrequency > adr x2, _gPcd_BinaryPatch_PcdSerialClockRate > str w0, [x2] > -#endif > > ret > > @@ -135,7 +133,6 @@ ASM_FUNC (ArmPlatformPeiBootAction) > .long 0 // end tag > .set .Lrevinfo_size, . - .Lrevinfo_buffer > > -#if (RPI_MODEL =3D=3D 3) > .align 4 > .Lclkinfo_buffer: > .long .Lclkinfo_size > @@ -148,7 +145,6 @@ ASM_FUNC (ArmPlatformPeiBootAction) > .long 0 // frequency > .long 0 // end tag > .set .Lclkinfo_size, . - .Lclkinfo_buffer > -#endif > > //UINTN > //ArmPlatformGetPrimaryCoreMpId ( > diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RP= i4/RPi4.dsc > index 2c05c31118d2..ff802d8347ea 100644 > --- a/Platform/RaspberryPi/RPi4/RPi4.dsc > +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc > @@ -429,7 +429,6 @@ [PcdsFixedAtBuild.common] > gArmPlatformTokenSpaceGuid.PL011UartClkInHz|48000000 > gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE > gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride|4 > - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|1000000000 > gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl|0x27 > gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize|8 > gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200 > @@ -465,6 +464,9 @@ [PcdsFixedAtBuild.common] > gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor|L"EDK2" > gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|TRUE > > +[PcdsPatchableInModule] > + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|500000000 > + > [PcdsDynamicHii.common.DEFAULT] > > # > @@ -621,7 +623,7 @@ [Components.common] > MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf > MdeModulePkg/Universal/SerialDxe/SerialDxe.inf { > > - SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualS= erialPortLib.inf > + SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualS= erialPortDxeLib.inf > } > Platform/RaspberryPi/Drivers/DisplayDxe/DisplayDxe.inf > EmbeddedPkg/Drivers/ConsolePrefDxe/ConsolePrefDxe.inf > -- > 2.29.2.windows.2 >