Topics

[edk2-platforms][PATCH v2 1/1] Platform/RaspberryPi: Fix mini UART clock divisor calculation


Mario Bălănică
 

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ă <mariobalanica02@gmail.com>
---
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 {
<LibraryClasses>
- 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
--
2.29.2.windows.2


Pete Batard
 

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ă <mariobalanica02@gmail.com>
---
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 {
<LibraryClasses>
- 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 <pete@akeo.ie>
Tested-by: Pete Batard <pete@akeo.ie>


Ard Biesheuvel
 

On Thu, 8 Apr 2021 at 11:47, Pete Batard <pete@akeo.ie> 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ă <mariobalanica02@gmail.com>
---
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 {

<LibraryClasses>

- 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 <pete@akeo.ie>
Tested-by: Pete Batard <pete@akeo.ie>
Thanks Pete.

Could anyone get me a version of this patch that is not whitespace
mangled? This one does not apply with 'git am'


Pete Batard
 

From: Mario B=C4=83l=C4=83nic=C4=83 <mariobalanica02@gmail.com>=0D

The VPU clock divisor has changed in this commit: https://github.com/raspbe=
rrypi/firmware/commit/1e5456a,=0D
thus breaking the mini UART clock divisor calculation on the Pi 4.=0D
=0D
Fix this by reading the core clock from the mailbox instead.=0D
=0D
Signed-off-by: Mario B=C4=83l=C4=83nic=C4=83 <mariobalanica02@gmail.com>=0D
---=0D
Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c | 15 =
+++------------=0D
Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S | 4 =
----=0D
Platform/RaspberryPi/RPi4/RPi4.dsc | 6 =
++++--=0D
3 files changed, 7 insertions(+), 18 deletions(-)=0D
=0D
diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortL=
ib.c b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c=0D
index 5e83bbf022eb..d2f983bf0a9f 100644=0D
--- a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c=0D
+++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c=0D
@@ -34,25 +34,16 @@ SerialPortGetDivisor (=0D
UINT32 SerialBaudRate=0D
)=0D
{=0D
- UINT64 BaseClockRate;=0D
+ UINT32 BaseClockRate;=0D
UINT32 Divisor;=0D
=0D
- //=0D
- // On the Raspberry Pi, the clock to use for the 16650-compatible UART=0D
- // is the base clock divided by the 12.12 fixed point VPU clock divisor.=
=0D
- //=0D
- BaseClockRate =3D (UINT64)PcdGet32 (PcdSerialClockRate);=0D
-#if (RPI_MODEL =3D=3D 4)=0D
- Divisor =3D MmioRead32(BCM2836_CM_BASE + BCM2836_CM_VPU_CLOCK_DIVISOR) &=
0xFFFFFF;=0D
- if (Divisor !=3D 0)=0D
- BaseClockRate =3D (BaseClockRate << 12) / Divisor;=0D
-#endif=0D
+ BaseClockRate =3D PcdGet32 (PcdSerialClockRate);=0D
=0D
//=0D
// As per the BCM2xxx datasheets:=0D
// baudrate =3D system_clock_freq / (8 * (divisor + 1)).=0D
//=0D
- Divisor =3D (UINT32)BaseClockRate / (SerialBaudRate * 8);=0D
+ Divisor =3D BaseClockRate / (SerialBaudRate * 8);=0D
if (Divisor !=3D 0) {=0D
Divisor--;=0D
}=0D
diff --git a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHe=
lper.S b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper=
.S=0D
index 58351e4fb8cc..7008aaf8aa4c 100644=0D
--- a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S=
=0D
+++ b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S=
=0D
@@ -85,13 +85,11 @@ ASM_FUNC (ArmPlatformPeiBootAction)=0D
adr x2, mBoardRevision=0D
str w0, [x2]=0D
=0D
-#if (RPI_MODEL =3D=3D 3)=0D
run .Lclkinfo_buffer=0D
=0D
ldr w0, .Lfrequency=0D
adr x2, _gPcd_BinaryPatch_PcdSerialClockRate=0D
str w0, [x2]=0D
-#endif=0D
=0D
ret=0D
=0D
@@ -135,7 +133,6 @@ ASM_FUNC (ArmPlatformPeiBootAction)=0D
.long 0 // end tag=0D
.set .Lrevinfo_size, . - .Lrevinfo_buffer=0D
=0D
-#if (RPI_MODEL =3D=3D 3)=0D
.align 4=0D
.Lclkinfo_buffer:=0D
.long .Lclkinfo_size=0D
@@ -148,7 +145,6 @@ ASM_FUNC (ArmPlatformPeiBootAction)=0D
.long 0 // frequency=0D
.long 0 // end tag=0D
.set .Lclkinfo_size, . - .Lclkinfo_buffer=0D
-#endif=0D
=0D
//UINTN=0D
//ArmPlatformGetPrimaryCoreMpId (=0D
diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4=
/RPi4.dsc=0D
index 2c05c31118d2..ff802d8347ea 100644=0D
--- a/Platform/RaspberryPi/RPi4/RPi4.dsc=0D
+++ b/Platform/RaspberryPi/RPi4/RPi4.dsc=0D
@@ -429,7 +429,6 @@ [PcdsFixedAtBuild.common]=0D
gArmPlatformTokenSpaceGuid.PL011UartClkInHz|48000000=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride|4=0D
- gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|1000000000=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl|0x27=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize|8=0D
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200=0D
@@ -465,6 +464,9 @@ [PcdsFixedAtBuild.common]=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor|L"EDK2"=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|TRUE=0D
=0D
+[PcdsPatchableInModule]=0D
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|500000000=0D
+=0D
[PcdsDynamicHii.common.DEFAULT]=0D
=0D
#=0D
@@ -621,7 +623,7 @@ [Components.common]=0D
MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf=0D
MdeModulePkg/Universal/SerialDxe/SerialDxe.inf {=0D
<LibraryClasses>=0D
- SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSer=
ialPortLib.inf=0D
+ SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSer=
ialPortDxeLib.inf=0D
}=0D
Platform/RaspberryPi/Drivers/DisplayDxe/DisplayDxe.inf=0D
EmbeddedPkg/Drivers/ConsolePrefDxe/ConsolePrefDxe.inf=0D
-- 2.29.2.windows.2=0D


Pete Batard
 

On 2021.04.08 12:06, Ard Biesheuvel wrote:
On Thu, 8 Apr 2021 at 11:47, Pete Batard <pete@akeo.ie> 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ă <mariobalanica02@gmail.com>
---
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 {

<LibraryClasses>

- 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 <pete@akeo.ie>
Tested-by: Pete Batard <pete@akeo.ie>
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


Ard Biesheuvel
 

On Thu, 8 Apr 2021 at 13:43, Pete Batard <pete@akeo.ie> wrote:

On 2021.04.08 12:06, Ard Biesheuvel wrote:
On Thu, 8 Apr 2021 at 11:47, Pete Batard <pete@akeo.ie> 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ă <mariobalanica02@gmail.com>
---
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 {

<LibraryClasses>

- 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 <pete@akeo.ie>
Tested-by: Pete Batard <pete@akeo.ie>
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.
Yes, which is odd given that I am receiving this email directly.

In any case, I still had to perform surgery on the patch to get it to apply.

Pushed as 7fe9704893f1..d2339f3c5f9a; mind double checking if I did
not break anything?

Thanks,
Ard.


Pete Batard
 

On 2021.04.08 13:26, Ard Biesheuvel wrote:
On Thu, 8 Apr 2021 at 13:43, Pete Batard <pete@akeo.ie> wrote:

On 2021.04.08 12:06, Ard Biesheuvel wrote:
On Thu, 8 Apr 2021 at 11:47, Pete Batard <pete@akeo.ie> 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ă <mariobalanica02@gmail.com>
---
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 {

<LibraryClasses>

- 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 <pete@akeo.ie>
Tested-by: Pete Batard <pete@akeo.ie>
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.
Yes, which is odd given that I am receiving this email directly.
In any case, I still had to perform surgery on the patch to get it to apply.
Pushed as 7fe9704893f1..d2339f3c5f9a; mind double checking if I did
not break anything?
Just re-tested with edk2-platforms latest, and everything looks good. Thanks.

/Pete

Thanks,
Ard.