From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.74]) by mx.groups.io with SMTP id smtpd.web09.9307.1582099927610715998 for ; Wed, 19 Feb 2020 00:12:08 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nxp1.onmicrosoft.com header.s=selector2-nxp1-onmicrosoft-com header.b=LMjnudtS; spf=pass (domain: oss.nxp.com, ip: 40.107.20.74, mailfrom: pankaj.bansal@oss.nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Es0F0QU9WsFYERo+HBTx+bnhGA9O0WA2GOx6ibsKznJONcRGSJZpBitqNKw6Ecob+OOSo3q3Hj3NnxdjG5+a6CIGd2LfNbeLWr3zkIwnw/h6FObRPUjuNCO90hnLjl0n4gucjES3H940bNfqjvwihwn6DQg9yroIzEIKUyBSlyrg6Xz4fEjJPP6JjGX7LDI3JjrsELH6WGRuenTfrDlipOHUwW7Uny/7vm+TBQLGhAKM9FwCt077TYosTQv+69LoKSbpXaU0VZrZhaVWdh4ruZHBWny18mS78+MkjDrPI9dflRR+fzOxccmwJXx6gaZged7WsTC01aDTMWJWDvwpAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=o0knI5IZ3nuMT+XeESkH90/kwcp+Wgyb8Rf9Udz1mKQ=; b=FT3zGls3CLI+RMgssjPyclBp42Kn455QkXoiNBzkS6q93KBCiaX7dgDsJZEGnu2/MY8xdo1n/cjq2eh12kUPRpDcVmKIcxw3t8fuYdBCaemSYxu+RAdN94w7FGgafXT5Ax+m9P+/bI1ja5+Eh2eEJC9yJg13AsLZeX+nkutvbmJtGb5lhd2tf3G625nsfXa3iXJUkhPuS9QRkR4Jb1nAhbjQx6BJfRFzXHZrOfejZ5SCy3PjRuqG7qIyaO/xCjHw5Uep3Jc7GVrMI7KmSg8gLvB6uMC3Yuhg7EMruk/CYwdxWLyKRn3pwhxvWpTbVTtsUfIPdbVvEeURhIEd/CDbwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=o0knI5IZ3nuMT+XeESkH90/kwcp+Wgyb8Rf9Udz1mKQ=; b=LMjnudtS/M/2VhNlzGQut7Y/iZDaEu/Ej7OC134r0nRhpNul4jlvs0w2oZSs+iVfEkrtnF2OL5DTuqDiH72QjsBkffjeZvlgOi+JRCYjb4lWqTsCUt0vbhS37yLxtcdaPAYURPd8xdkjGEphvhP+JduXNmjWzMoivXrHulvIiwg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pankaj.bansal@oss.nxp.com; Received: from VI1PR0401MB2496.eurprd04.prod.outlook.com (10.168.65.10) by VI1PR0401MB2237.eurprd04.prod.outlook.com (10.169.132.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.24; Wed, 19 Feb 2020 08:12:05 +0000 Received: from VI1PR0401MB2496.eurprd04.prod.outlook.com ([fe80::196a:28a9:bb9:2fae]) by VI1PR0401MB2496.eurprd04.prod.outlook.com ([fe80::196a:28a9:bb9:2fae%9]) with mapi id 15.20.2729.033; Wed, 19 Feb 2020 08:12:05 +0000 From: Pankaj Bansal To: Jian J Wang , Hao A Wu , Ray Ni , Maurice Ma , Guo Dong , Benjamin You , Leif Lindholm , Meenakshi Aggarwal , Varun Sethi CC: devel@edk2.groups.io, Pankaj Bansal Subject: [PATCH 1/1] MdeModulePkg: UART Dynamic clock freq Support Date: Wed, 19 Feb 2020 19:01:35 +0530 Message-ID: <20200219133135.10407-2-pankaj.bansal@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219133135.10407-1-pankaj.bansal@oss.nxp.com> References: <20200219133135.10407-1-pankaj.bansal@oss.nxp.com> X-ClientProxiedBy: TY1PR01CA0141.jpnprd01.prod.outlook.com (2603:1096:402:1::17) To VI1PR0401MB2496.eurprd04.prod.outlook.com (2603:10a6:800:56::10) Return-Path: pankaj.bansal@oss.nxp.com MIME-Version: 1.0 Received: from uefi-workstation.ap.freescale.net (92.120.1.69) by TY1PR01CA0141.jpnprd01.prod.outlook.com (2603:1096:402:1::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.18 via Frontend Transport; Wed, 19 Feb 2020 08:12:00 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [92.120.1.69] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9bcf8cee-d2c1-404d-cdcc-08d7b5136822 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2237:|VI1PR0401MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:331; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(346002)(39860400002)(396003)(366004)(376002)(136003)(189003)(199004)(6506007)(186003)(86362001)(478600001)(19627235002)(6486002)(44832011)(66556008)(4326008)(16526019)(52116002)(2616005)(956004)(26005)(2906002)(1076003)(81166006)(8676002)(6512007)(8936002)(81156014)(316002)(66476007)(110136005)(66946007)(6666004)(5660300002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0401MB2237;H:VI1PR0401MB2496.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:0; Received-SPF: None (protection.outlook.com: oss.nxp.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JWITW5SGaydGqEv4ekf6KJoTbowpWR399uN/h4cAa0Gtb5aSZdrOzKZWxRtEvmlt59wOPA+jDdRs5Fr0HUj7p3En5yoFfegh1a+myyUPAkvV52rAuqF1qt6rbztzZWfWqAzAKpFZ6yFUFrZ0wEY2YcTzvdleDmk4nTOmH8CMW7z/Oejnqh+Xwi7LRt8nSZV7GJbSV8RJsi37B34jDfKg9LyaN/7EXSbrKM3UQUygX+d81QELIs6H7wJdAZe+mL/V/ilIk+DQEjd0dogVYDmL/uFiwSz0cWxg6UeD4MckRU5uiDhcYnRDgc35Ok8di7Vq6ZCKCJRD9XodmOvBEgdmTJm9NnSvTtr24d6qLZQ+Am6CQE4oRv5Dnx0KPVCT46t64VITvvKuU7OorOib7h5X16zlgVTVYW2xoFOneiJhuZiJQGWTRgosvKVz1ss2L87d X-MS-Exchange-AntiSpam-MessageData: 6AnHFsxTiDXXBQj/SQOhjqhbMe7ZafveDazpidvLQN9c2x28RNd9ho1to/1G1hBIJ8z3pkwJIC5/qzI1qfobM3TABCXNOiYaBGiUPwl7L2Pr61VNFHjvH8atvIbNjIsr0Hy52R4ImrcSmTTSP5jYrg== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9bcf8cee-d2c1-404d-cdcc-08d7b5136822 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 08:12:05.5770 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Uu0lFcbO1nGF3OKCgRXpcS/aTQPvhDoDzmEfeLk+FMvQyVxPqMGeDaVvi39RblYGGXTt6v2bTfxNMc9CGaH/hg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2237 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Pankaj Bansal 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 --- .../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/BaseSerialU= artClockLib.c create mode 100644 MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialU= artClockLib.inf diff --git a/MdeModulePkg/Include/Library/SerialUartClockLib.h b/MdeModuleP= kg/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/BaseSerialPortLib1= 6550.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 #include #include +#include #include =20 // @@ -501,8 +502,8 @@ SerialPortInitialize ( // Calculate divisor for baud generator // Ref_Clk_Rate / Baud_Rate / 16 // - Divisor =3D PcdGet32 (PcdSerialClockRate) / (PcdGet32 (PcdSerialBaudRate= ) * 16); - if ((PcdGet32 (PcdSerialClockRate) % (PcdGet32 (PcdSerialBaudRate) * 16)= ) >=3D PcdGet32 (PcdSerialBaudRate) * 8) { + Divisor =3D BaseSerialPortGetClock () / (PcdGet32 (PcdSerialBaudRate) * = 16); + if ((BaseSerialPortGetClock () % (PcdGet32 (PcdSerialBaudRate) * 16)) >= =3D PcdGet32 (PcdSerialBaudRate) * 8) { Divisor++; } =20 @@ -1080,8 +1081,8 @@ SerialPortSetAttributes ( // Calculate divisor for baud generator // Ref_Clk_Rate / Baud_Rate / 16 // - Divisor =3D PcdGet32 (PcdSerialClockRate) / (SerialBaudRate * 16); - if ((PcdGet32 (PcdSerialClockRate) % (SerialBaudRate * 16)) >=3D SerialB= audRate * 8) { + Divisor =3D BaseSerialPortGetClock () / (SerialBaudRate * 16); + if ((BaseSerialPortGetClock () % (SerialBaudRate * 16)) >=3D SerialBaudR= ate * 8) { Divisor++; } =20 diff --git a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib1= 6550.inf b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib165= 50.inf index 8b4ae3f1d4ee..b4c16504f211 100644 --- a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.in= f +++ b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.in= f @@ -24,6 +24,7 @@ [LibraryClasses] IoLib PlatformHookLib PciLib + SerialUartClockLib =20 [Sources] BaseSerialPortLib16550.c @@ -37,7 +38,6 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate ## CONSU= MES gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl ## CONSU= MES gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl ## CONSU= MES - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate ## CONSU= MES gEfiMdeModulePkgTokenSpaceGuid.PcdSerialPciDeviceInfo ## CONSU= MES gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize ## CONSU= MES gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSU= MES diff --git a/MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartCloc= kLib.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 +#include + +/** + Return clock in for Uart IP + + @return Pcd PcdSerialClockRate +**/ +UINT32 +EFIAPI +BaseSerialPortGetClock ( + VOID + ) +{ + return PcdGet32 (PcdSerialClockRate); +} diff --git a/MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartCloc= kLib.inf b/MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockL= ib.inf new file mode 100644 index 000000000000..91ba69436ed6 --- /dev/null +++ b/MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.in= f @@ -0,0 +1,27 @@ +#/* @file +# Copyright 2020 NXP +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#*/ + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D BaseSerialUartClockLib + FILE_GUID =3D fa65495e-d3c8-4ea3-9737-994e9ccbaf11 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SerialUartClockLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Sources.common] + BaseSerialUartClockLib.c + +[LibraryClasses] + PcdLib + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate ## CONSU= MES 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/DxeS= ecurityManagementLib.inf TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplat= e.inf + SerialUartClockLib|MdeModulePkg/Library/BaseSerialUartClockLib/BaseSeria= lUartClockLib.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/RuntimeDxeReportStatu= sCodeLib.inf MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.inf + MdeModulePkg/Library/BaseSerialUartClockLib/BaseSerialUartClockLib.inf MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf MdeModulePkg/Library/DxeDebugPrintErrorLevelLib/DxeDebugPrintErrorLevelL= ib.inf diff --git a/SourceLevelDebugPkg/SourceLevelDebugPkg.dsc b/SourceLevelDebug= Pkg/SourceLevelDebugPkg.dsc index a1a1b81d03cb..c0ad88f26341 100644 --- a/SourceLevelDebugPkg/SourceLevelDebugPkg.dsc +++ b/SourceLevelDebugPkg/SourceLevelDebugPkg.dsc @@ -33,6 +33,7 @@ [LibraryClasses.common] SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchroniza= tionLib.inf LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeC= offGetEntryPointLib.inf + SerialUartClockLib|MdeModulePkg/Library/BaseSerialUartClockLib/BaseSeria= lUartClockLib.inf SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPort= Lib16550.inf PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDeb= ug/PeCoffExtraActionLibDebug.inf TimerLib|UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUe= fiCpu.inf diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc b/UefiPayloadPkg/UefiPay= loadPkgIa32.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/BaseSeria= lUartClockLib.inf SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPort= Lib16550.inf PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.i= nf PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/Pla= tformBootManagerLib.inf diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc b/UefiPayloadPkg/Uefi= PayloadPkgIa32X64.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/BaseSeria= lUartClockLib.inf SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPort= Lib16550.inf PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.i= nf PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/Pla= tformBootManagerLib.inf --=20 2.17.1