[edk2-devel] [PATCH 1/1] MdeModulePkg: UART Dynamic clock freq Support

Leif Lindholm leif at nuviainc.com
Thu Mar 19 15:30:57 UTC 2020


Hi Ray,

I agree it would be nice, but if not - this lets us get rid of
otherwise needless driver duplication. To me, that makes it worth a
little trivial churn.

/
    Leif

On Thu, Mar 19, 2020 at 15:09:19 +0000, Ni, Ray wrote:
> It seems this change requires all platforms DSC to include the new library class/instance.
> 
> Is there a way that can avoid the platform impact?
> 
> Thanks,
> Ray
> 
> > -----Original Message-----
> > From: Pankaj Bansal <pankaj.bansal at oss.nxp.com>
> > Sent: Wednesday, February 19, 2020 9:32 PM
> > To: Wang, Jian J <jian.j.wang at intel.com>; Wu, Hao A <hao.a.wu at intel.com>; Ni, Ray <ray.ni at intel.com>; Ma, Maurice
> > <maurice.ma at intel.com>; Dong, Guo <guo.dong at intel.com>; You, Benjamin <benjamin.you at intel.com>; Leif Lindholm
> > <leif at nuviainc.com>; Meenakshi Aggarwal <meenakshi.aggarwal at nxp.com>; Varun Sethi <V.Sethi at nxp.com>
> > Cc: devel at edk2.groups.io; Pankaj Bansal <pankaj.bansal at nxp.com>
> > Subject: [PATCH 1/1] MdeModulePkg: UART Dynamic clock freq Support
> > 
> > From: Pankaj Bansal <pankaj.bansal at nxp.com>
> > 
> > Some platform support dynamic clocking, which is controlled by some
> > jumper setting or hardware registers. Result of that is that PCD
> > PcdSerialClockRate would need to be updated for frequency change.
> > 
> > This patch implements support for dynamic frequency for Uart.
> > 
> > This patch implements default lib, which is using Pcd. Platform which
> > needs dynamic clocking needs implement SerialUartClockLib
> > 
> > This patch is based on ArmPlatformPkg/Library/PL011UartClockLib
> > 
> > Signed-off-by: Pankaj Bansal <pankaj.bansal at nxp.com>
> > ---
> >  .../Include/Library/SerialUartClockLib.h      | 21 +++++++++++++++
> >  .../BaseSerialPortLib16550.c                  |  9 ++++---
> >  .../BaseSerialPortLib16550.inf                |  2 +-
> >  .../BaseSerialUartClockLib.c                  | 24 +++++++++++++++++
> >  .../BaseSerialUartClockLib.inf                | 27 +++++++++++++++++++
> >  MdeModulePkg/MdeModulePkg.dsc                 |  2 ++
> >  SourceLevelDebugPkg/SourceLevelDebugPkg.dsc   |  1 +
> >  UefiPayloadPkg/UefiPayloadPkgIa32.dsc         |  1 +
> >  UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc      |  1 +
> >  9 files changed, 83 insertions(+), 5 deletions(-)
> >  create mode 100644 MdeModulePkg/Include/Library/SerialUartClockLib.h
> >  create mode 100644 MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.c
> >  create mode 100644 MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.inf
> > 
> > diff --git a/MdeModulePkg/Include/Library/SerialUartClockLib.h b/MdeModulePkg/Include/Library/SerialUartClockLib.h
> > new file mode 100644
> > index 000000000000..b6b16f71d4cf
> > --- /dev/null
> > +++ b/MdeModulePkg/Include/Library/SerialUartClockLib.h
> > @@ -0,0 +1,21 @@
> > +/** @file
> > +*
> > +*  Copyright 2020 NXP
> > +*
> > +*  SPDX-License-Identifier: BSD-2-Clause-Patent
> > +*
> > +**/
> > +
> > +#ifndef SERIAL_UART_CLOCK_LIB_H__
> > +#define SERIAL_UART_CLOCK_LIB_H__
> > +
> > +/**
> > +  Return clock in for Uart IP
> > +**/
> > +UINT32
> > +EFIAPI
> > +BaseSerialPortGetClock (
> > +  VOID
> > +  );
> > +
> > +#endif
> > diff --git a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c
> > b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c
> > index 9cb50dd80d56..2e0c05d5789e 100644
> > --- a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c
> > +++ b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c
> > @@ -16,6 +16,7 @@
> >  #include <Library/IoLib.h>
> >  #include <Library/PciLib.h>
> >  #include <Library/PlatformHookLib.h>
> > +#include <Library/SerialUartClockLib.h>
> >  #include <Library/BaseLib.h>
> > 
> >  //
> > @@ -501,8 +502,8 @@ SerialPortInitialize (
> >    // Calculate divisor for baud generator
> >    //    Ref_Clk_Rate / Baud_Rate / 16
> >    //
> > -  Divisor = PcdGet32 (PcdSerialClockRate) / (PcdGet32 (PcdSerialBaudRate) * 16);
> > -  if ((PcdGet32 (PcdSerialClockRate) % (PcdGet32 (PcdSerialBaudRate) * 16)) >= PcdGet32 (PcdSerialBaudRate) * 8) {
> > +  Divisor = BaseSerialPortGetClock () / (PcdGet32 (PcdSerialBaudRate) * 16);
> > +  if ((BaseSerialPortGetClock () % (PcdGet32 (PcdSerialBaudRate) * 16)) >= PcdGet32 (PcdSerialBaudRate) * 8) {
> >      Divisor++;
> >    }
> > 
> > @@ -1080,8 +1081,8 @@ SerialPortSetAttributes (
> >    // Calculate divisor for baud generator
> >    //    Ref_Clk_Rate / Baud_Rate / 16
> >    //
> > -  Divisor = PcdGet32 (PcdSerialClockRate) / (SerialBaudRate * 16);
> > -  if ((PcdGet32 (PcdSerialClockRate) % (SerialBaudRate * 16)) >= SerialBaudRate * 8) {
> > +  Divisor = BaseSerialPortGetClock () / (SerialBaudRate * 16);
> > +  if ((BaseSerialPortGetClock () % (SerialBaudRate * 16)) >= SerialBaudRate * 8) {
> >      Divisor++;
> >    }
> > 
> > diff --git a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
> > b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
> > index 8b4ae3f1d4ee..b4c16504f211 100644
> > --- a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
> > +++ b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
> > @@ -24,6 +24,7 @@ [LibraryClasses]
> >    IoLib
> >    PlatformHookLib
> >    PciLib
> > +  SerialUartClockLib
> > 
> >  [Sources]
> >    BaseSerialPortLib16550.c
> > @@ -37,7 +38,6 @@ [Pcd]
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate                ## CONSUMES
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl             ## CONSUMES
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl             ## CONSUMES
> > -  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate               ## CONSUMES
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdSerialPciDeviceInfo           ## CONSUMES
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize      ## CONSUMES
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride          ## CONSUMES
> > diff --git a/MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.c
> > b/MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.c
> > new file mode 100644
> > index 000000000000..7a0d0427cc4e
> > --- /dev/null
> > +++ b/MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.c
> > @@ -0,0 +1,24 @@
> > +/** @file
> > +*
> > +*  Copyright 2020 NXP
> > +*
> > +*  SPDX-License-Identifier: BSD-2-Clause-Patent
> > +*
> > +**/
> > +
> > +#include <Base.h>
> > +#include <Library/PcdLib.h>
> > +
> > +/**
> > +  Return clock in for Uart IP
> > +
> > +  @return Pcd PcdSerialClockRate
> > +**/
> > +UINT32
> > +EFIAPI
> > +BaseSerialPortGetClock (
> > +  VOID
> > +  )
> > +{
> > +  return PcdGet32 (PcdSerialClockRate);
> > +}
> > diff --git a/MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.inf
> > b/MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.inf
> > new file mode 100644
> > index 000000000000..91ba69436ed6
> > --- /dev/null
> > +++ b/MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.inf
> > @@ -0,0 +1,27 @@
> > +#/* @file
> > +#  Copyright 2020 NXP
> > +#
> > +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> > +#
> > +#*/
> > +
> > +[Defines]
> > +  INF_VERSION                    = 0x0001001A
> > +  BASE_NAME                      = BaseSerialUartClockLib
> > +  FILE_GUID                      = fa65495e-d3c8-4ea3-9737-994e9ccbaf11
> > +  MODULE_TYPE                    = BASE
> > +  VERSION_STRING                 = 1.0
> > +  LIBRARY_CLASS                  = SerialUartClockLib
> > +
> > +[Packages]
> > +  MdePkg/MdePkg.dec
> > +  MdeModulePkg/MdeModulePkg.dec
> > +
> > +[Sources.common]
> > +  BaseSerialUartClockLib.c
> > +
> > +[LibraryClasses]
> > +  PcdLib
> > +
> > +[Pcd]
> > +  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate               ## CONSUMES
> > diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
> > index f7dbb27ce25d..d581ca797b3b 100644
> > --- a/MdeModulePkg/MdeModulePkg.dsc
> > +++ b/MdeModulePkg/MdeModulePkg.dsc
> > @@ -65,6 +65,7 @@ [LibraryClasses]
> >    UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
> >    SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
> >    TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
> > +  SerialUartClockLib|MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.inf
> >    SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
> >    CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
> >    PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
> > @@ -292,6 +293,7 @@ [Components]
> >    MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
> >    MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeReportStatusCodeLib.inf
> >    MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.inf
> > +  MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.inf
> >    MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
> >    MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf
> >    MdeModulePkg/Library/DxeDebugPrintErrorLevelLib/DxeDebugPrintErrorLevelLib.inf
> > diff --git a/SourceLevelDebugPkg/SourceLevelDebugPkg.dsc b/SourceLevelDebugPkg/SourceLevelDebugPkg.dsc
> > index a1a1b81d03cb..c0ad88f26341 100644
> > --- a/SourceLevelDebugPkg/SourceLevelDebugPkg.dsc
> > +++ b/SourceLevelDebugPkg/SourceLevelDebugPkg.dsc
> > @@ -33,6 +33,7 @@ [LibraryClasses.common]
> >    SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
> >    LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
> >    PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
> > +  SerialUartClockLib|MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.inf
> >    SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
> >    PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf
> >    TimerLib|UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUefiCpu.inf
> > diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc b/UefiPayloadPkg/UefiPayloadPkgIa32.dsc
> > index d52945442e0e..a556a32b272c 100644
> > --- a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc
> > +++ b/UefiPayloadPkg/UefiPayloadPkgIa32.dsc
> > @@ -174,6 +174,7 @@ [LibraryClasses]
> >    #
> >    TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf
> >    ResetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf
> > +  SerialUartClockLib|MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.inf
> >    SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
> >    PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf
> >    PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
> > diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc b/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc
> > index 0736cd995476..7e86375fe57d 100644
> > --- a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc
> > +++ b/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc
> > @@ -175,6 +175,7 @@ [LibraryClasses]
> >    #
> >    TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf
> >    ResetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf
> > +  SerialUartClockLib|MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.inf
> >    SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
> >    PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf
> >    PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
> > --
> > 2.17.1
> 

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#55994): https://edk2.groups.io/g/devel/message/55994
Mute This Topic: https://groups.io/mt/71393886/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list