From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by mx.groups.io with SMTP id smtpd.web08.6658.1617882217143180463 for ; Thu, 08 Apr 2021 04:43:37 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=VFC1FwCy; spf=pass (domain: akeo.ie, ip: 209.85.128.47, mailfrom: pete@akeo.ie) Received: by mail-wm1-f47.google.com with SMTP id t5-20020a1c77050000b029010e62cea9deso1086516wmi.0 for ; Thu, 08 Apr 2021 04:43:36 -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=eWeoPAqteFP46CTTqZHc9tNprYaaSOpriUo3kUS2Cpc=; b=VFC1FwCyCllPRaxGbq5Upjum+FlFYq6rMLhe/O0Z+D9v7+D5k7FeoGpnymwsrJAELJ a2lrk4ZeX4NCJyC1/xClHS3P4Jcf7YObzbSqLaTNkqBbG4AQ5uT5aUhZJICcVS4qzX3A pL0qq15ywe7xK189D1EALbfCwcNrEaVbie76/4bQ30gyCDsb8EMLajWgCxN29I/zRmRT 8hLiKxePyNQZeqQN6XkxNZDOAVKsqf86B8CiFp6Og+y8EtIHm4Gg4Qd+kph1yovF8KY7 6DgC4uJA3Rbye+2gyADLpGMDD/mfY7+ME5mRFr+dHXquU+aoshoUWyOpLnsZ+vGaU693 fC0A== 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=eWeoPAqteFP46CTTqZHc9tNprYaaSOpriUo3kUS2Cpc=; b=tkp37lXEbUveLBWNKxY1tkPYyuCnSckgszKCzzUeRkSlMuBu1R896eu+rnPG4mxwzK bpGi2xIDaguhvYcWYQ1b7aqofWVGb98wjx/ykGCdC4eGlYyt2j7IlB5ap9nt9XNPGk17 Pc6gkMfqL7P+LSLLFpuncCL61rOQekeY01rWVpbNiAKeuzSvLWPDcZFT4PD+qKcAYR8r J+rvsDh1p5XyaJuaFY2Q0xkOTCHRW1Z5PfNuOEO5lOiY5gY1h09SiRQAHzZg0kKkX6y3 VtA5kXzmbTvLC1OnPkShpzajXhAVAzYr4v5bXkVQnN+/jqA6Ao0WKOpSicLAidy+M+XR an6g== X-Gm-Message-State: AOAM533iKod96/DuxxARyEqAs2pEzwW+/OEYWlgZMHK8aXSyTQ1xbeP9 3PnXMNPyYzcP0I2Z7ZsQXzyh8X9WT3YU9g== X-Google-Smtp-Source: ABdhPJy/+uCg9OHUqNT9HFalPNY9P8lRGBdOzOfk87Y0JfuvVeyqXRolaWYbBLURaRB0xcKQ3hEX4Q== X-Received: by 2002:a7b:c5d2:: with SMTP id n18mr7847455wmk.53.1617882215543; Thu, 08 Apr 2021 04:43:35 -0700 (PDT) Return-Path: Received: from [10.0.0.122] ([84.203.65.130]) by smtp.googlemail.com with ESMTPSA id y17sm12105078wmo.42.2021.04.08.04.43.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Apr 2021 04:43:35 -0700 (PDT) Subject: Re: [edk2-platforms][PATCH v2 1/1] Platform/RaspberryPi: Fix mini UART clock divisor calculation To: Ard Biesheuvel Cc: =?UTF-8?B?TWFyaW8gQsSDbMSDbmljxIM=?= , devel@edk2.groups.io, Ard Biesheuvel , Leif Lindholm References: <20210406140411.901-1-mariobalanica02@gmail.com> <45e921e6-edd7-a365-71c2-00383e76d5ea@akeo.ie> From: "Pete Batard" Message-ID: Date: Thu, 8 Apr 2021 12:43:34 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit On 2021.04.08 12:06, Ard Biesheuvel wrote: > On Thu, 8 Apr 2021 at 11:47, Pete Batard wrote: >> >> On 2021.04.06 15:04, Mario Bălănică wrote: >>> The VPU clock divisor has changed in this commit: >>> https://github.com/raspberrypi/firmware/commit/1e5456a, >>> thus breaking the mini UART clock divisor calculation on the Pi 4. >>> >>> Fix this by reading the core clock from the mailbox instead. >>> >>> Signed-off-by: Mario Bălănică >>> --- >>> Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c | 15 +++------------ >>> 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/DualSerialPortLib.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 divisor. >>> >>> - // >>> >>> - BaseClockRate = (UINT64)PcdGet32 (PcdSerialClockRate); >>> >>> -#if (RPI_MODEL == 4) >>> >>> - Divisor = MmioRead32(BCM2836_CM_BASE + BCM2836_CM_VPU_CLOCK_DIVISOR) & 0xFFFFFF; >>> >>> - if (Divisor != 0) >>> >>> - BaseClockRate = (BaseClockRate << 12) / Divisor; >>> >>> -#endif >>> >>> + BaseClockRate = PcdGet32 (PcdSerialClockRate); >>> >>> >>> >>> // >>> >>> // As per the BCM2xxx datasheets: >>> >>> // baudrate = system_clock_freq / (8 * (divisor + 1)). >>> >>> // >>> >>> - Divisor = (UINT32)BaseClockRate / (SerialBaudRate * 8); >>> >>> + Divisor = BaseClockRate / (SerialBaudRate * 8); >>> >>> if (Divisor != 0) { >>> >>> Divisor--; >>> >>> } >>> >>> diff --git a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.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 == 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 == 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/RPi4/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/DualSerialPortLib.inf >>> >>> + SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortDxeLib.inf >>> >>> } >>> >>> Platform/RaspberryPi/Drivers/DisplayDxe/DisplayDxe.inf >>> >>> EmbeddedPkg/Drivers/ConsolePrefDxe/ConsolePrefDxe.inf >>> >> >> Reviewed-by: Pete Batard >> Tested-by: Pete Batard > > Thanks Pete. > > Could anyone get me a version of this patch that is not whitespace > mangled? This one does not apply with 'git am' > Done. The version I sent is the one I applied & tested after I ran it through my unmangling script to remove the extra lines. Not sure if it'll still not be re-mangled by the list processing though. Regards, /Pete