From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (EUR01-HE1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web09.1387.1581060258704904576 for ; Thu, 06 Feb 2020 23:24:21 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nxp.com header.s=selector2 header.b=LMJdEybo; spf=fail (domain: nxp.com, ip: , mailfrom: pankaj.bansal@nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZKeAzEEZ4cxMW94MnZxU3oKUD2k6JT7Um7JSTLp2gxgvMuNRfKV8CtwDK4y70mO1K5lnIFIK9MtK9zAgfNyA3BDMGWAIzyiTaJf3GVvRh+99KQglYXIXLIr2ue9K/Teqv06zrnq/oguMajIc05lTcgg5ne9E6Xz526FTAlWj1hx0N0A3K7+i7lMV+ukpLnOYgCHbOEWy7YRG5Xxc5HsZIJR/EqNcy/6tQndqZ8yTLFT2cJ81rAsyuz6lgYgWRhd8CIrz45VaYcuZ8AHIfWjZ5H62eAR8GzlKQrYsHW00fYJ8lLEzKirbDAJL0JlNYiJXVzpwol6HvzIGPwR82hdqbQ== 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=zyaFUnDtcXyTRexaAm52O7dxSl35NCNwO2D72/tVs5A=; b=EE6i6b2Fc4awSUJlQ06C4EtVDvpcBBsPQlZqcBvjO4NrnctyydXijYvpdy9tvVum5gs0yM8m6FN8+287DRSKRieVpONqoQQ30CQ7MNNQZdQMHBABHDEnBECvhzV9ioZOEjySlgcL6LLkD3VmdiDc8V3uZZJyzRZkTTVNI00EzXbrg97KULeu5ZZbr6EyqXRA812dSlmodSrQ08aTQOFV7DpiFU0c0NVL7pfKsb0fSoypyfz5rt6oiJXwDmtFyGY690Y1GvXPuX/Vk7mlmwuLfARMu7Fq28j+8nxytlrB8kQm7W2q15aSICQm55NLa4JVgTaNaqsW/E1l0WRaOteqnQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zyaFUnDtcXyTRexaAm52O7dxSl35NCNwO2D72/tVs5A=; b=LMJdEyboT7SRArbkk8eB9OBS1oGoo88rvHsRe+Lhz/63HxwRUGBoIK2ETanSglYfhvxMVECyPE+2a1xIHqGzliUyBJ/MkTAiFmF4SyeX9tqAEGXfHgEPheqHAClBHT74eKGGSwdg6Ga3uQnvAtJq7k9VS3nIOQtQ/xSFJZm3NiM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pankaj.bansal@nxp.com; Received: from VI1PR0401MB2496.eurprd04.prod.outlook.com (10.168.65.10) by VI1PR0401MB2575.eurprd04.prod.outlook.com (10.168.62.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.21; Fri, 7 Feb 2020 07:24:19 +0000 Received: from VI1PR0401MB2496.eurprd04.prod.outlook.com ([fe80::8823:663d:c6ed:cbd6]) by VI1PR0401MB2496.eurprd04.prod.outlook.com ([fe80::8823:663d:c6ed:cbd6%12]) with mapi id 15.20.2686.036; Fri, 7 Feb 2020 07:24:19 +0000 From: "Pankaj Bansal" To: Leif Lindholm , Meenakshi Aggarwal , Michael D Kinney , Varun Sethi Cc: devel@edk2.groups.io, Pankaj Bansal Subject: [PATCH 16/19] Silicon/NXP: Add Pl011 Serial port lib Date: Fri, 7 Feb 2020 18:13:25 +0530 Message-Id: <20200207124328.8723-17-pankaj.bansal@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200207124328.8723-1-pankaj.bansal@nxp.com> References: <20200207124328.8723-1-pankaj.bansal@nxp.com> X-ClientProxiedBy: PN1PR01CA0103.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00::19) To VI1PR0401MB2496.eurprd04.prod.outlook.com (2603:10a6:800:56::10) Return-Path: pankaj.bansal@nxp.com MIME-Version: 1.0 Received: from uefi-workstation.ap.freescale.net (92.120.1.69) by PN1PR01CA0103.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.21 via Frontend Transport; Fri, 7 Feb 2020 07:24:18 +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: 6708bfd6-c87c-4de4-bbd0-08d7ab9ebef2 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2575:|VI1PR0401MB2575: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-Forefront-PRVS: 0306EE2ED4 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(346002)(366004)(376002)(39860400002)(136003)(396003)(189003)(199004)(6512007)(478600001)(86362001)(66556008)(66476007)(66946007)(52116002)(6636002)(5660300002)(19627235002)(6486002)(316002)(956004)(6666004)(26005)(8936002)(2616005)(16526019)(186003)(4326008)(44832011)(110136005)(36756003)(1076003)(8676002)(81156014)(81166006)(2906002)(6506007);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0401MB2575;H:VI1PR0401MB2496.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KQ6N/6P4T3oGHFkksrVYTZ30zC8nSHOYJ394tokjQBq3Xuiq6W95ihXoSDpPXfKnIpg66aA50AqI8tfylBMmzz7f3iNVVjCQ/jJbs4g6uk+OeWbCreAeDry4s8+JWRzp0YlzuJ2q7e+q9oVNAaST7K79mfDJplHqkdxF2DhI4ORKKFjVLLY9U450XRGv2SsrGNo4XTzRdSruZ2TmuhOOUcVZYmuvX5HdboysLln4AXFgIcS686TncXhvaiCHpsQ+xLXW+2i9fMKKCvm1J/ZpkWrFFdsnVOdc/Wq27AITPvGGodkO8vYMrgAVHZ11L6f5uLCWrtjCKl0aLNynMWizdbUWvPIvtQHb3dxS5K4njfMsSGR2pZN3PNle2ezRziRSfWFpoz8+ESaiKPtSmUNM8SQN8M+HtBn6FwzD1k2gZjWsnWRvxh6o70HzGlq2Bn4k X-MS-Exchange-AntiSpam-MessageData: 0xSgs4rsJSI/XPPacYpuvk/xkNjhl5+Tovh9CTNlO1msUpiXJ2RAhq2/0jmi71g5xIteN77F6/1Wh6TF+B3qmUFzs7AAWsm4jww1+C8BvXhhiL8fSqaGo50JqZsljPUQdBsRq/dvF+Uk1qQQ5+8RWQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6708bfd6-c87c-4de4-bbd0-08d7ab9ebef2 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2020 07:24:19.4894 (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: E+ZKawyQrIN/eteuNyJpyx3mxRTchFGn9kCBrDs+GyIS1Y18exonjjfh91Zqbwp2vHLrOJuI+Q3H/OLdkI9Xrw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2575 Content-Type: text/plain Use ArmPlatformPkg/PL011SerialPortLib with some changes: 1. add Get clock API to get the UART clock from ArmPlatformLib 2. remove SerialPortInitalize functionality This is same as being done in Silicon/NXP/Library/BaseSerialPortLib16550. Signed-off-by: Pankaj Bansal --- .../PL011SerialPortLib/PL011SerialPortLib.c | 229 ++++++++++++++++++ .../PL011SerialPortLib/PL011SerialPortLib.inf | 42 ++++ Silicon/NXP/NxpQoriqLs.dsc.inc | 1 + 3 files changed, 272 insertions(+) create mode 100644 Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.c create mode 100644 Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.inf diff --git a/Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.c b/Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.c new file mode 100644 index 0000000000..35cfe8e324 --- /dev/null +++ b/Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.c @@ -0,0 +1,229 @@ +/** @file + Serial I/O Port library functions with no library constructor/destructor + + Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+ Copyright (c) 2012 - 2016, ARM Ltd. All rights reserved.
+ Copyright (c) 2015, Intel Corporation. All rights reserved.
+ Copyright 2020 NXP + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include +#include + +extern NXP_PLATFORM_GET_CLOCK_PPI mPlatformGetClockPpi; + +/** Initialise the serial device hardware with default settings. + + @retval RETURN_SUCCESS The serial device was initialised. + @retval RETURN_INVALID_PARAMETER One or more of the default settings + has an unsupported value. + **/ +RETURN_STATUS +EFIAPI +SerialPortInitialize ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + Write data to serial device. + + @param Buffer Point of data buffer which need to be written. + @param NumberOfBytes Number of output bytes which are cached in Buffer. + + @retval 0 Write data failed. + @retval !0 Actual number of bytes written to serial device. + +**/ +UINTN +EFIAPI +SerialPortWrite ( + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + return PL011UartWrite ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes); +} + +/** + Read data from serial device and save the data in buffer. + + @param Buffer Point of data buffer which need to be written. + @param NumberOfBytes Number of output bytes which are cached in Buffer. + + @retval 0 Read data failed. + @retval !0 Actual number of bytes read from serial device. + +**/ +UINTN +EFIAPI +SerialPortRead ( + OUT UINT8 *Buffer, + IN UINTN NumberOfBytes +) +{ + return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes); +} + +/** + Check to see if any data is available to be read from the debug device. + + @retval TRUE At least one byte of data is available to be read + @retval FALSE No data is available to be read + +**/ +BOOLEAN +EFIAPI +SerialPortPoll ( + VOID + ) +{ + return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase)); +} +/** + Set new attributes to PL011. + + @param BaudRate The baud rate of the serial device. If the + baud rate is not supported, the speed will + be reduced down to the nearest supported one + and the variable's value will be updated + accordingly. + @param ReceiveFifoDepth The number of characters the device will + buffer on input. If the specified value is + not supported, the variable's value will + be reduced down to the nearest supported one. + @param Timeout If applicable, the number of microseconds the + device will wait before timing out a Read or + a Write operation. + @param Parity If applicable, this is the EFI_PARITY_TYPE + that is computed or checked as each character + is transmitted or received. If the device + does not support parity, the value is the + default parity value. + @param DataBits The number of data bits in each character + @param StopBits If applicable, the EFI_STOP_BITS_TYPE number + of stop bits per character. If the device + does not support stop bits, the value is the + default stop bit value. + + @retval EFI_SUCCESS All attributes were set correctly. + @retval EFI_INVALID_PARAMETERS One or more attributes has an unsupported + value. + @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly. + +**/ +RETURN_STATUS +EFIAPI +SerialPortSetAttributes ( + IN OUT UINT64 *BaudRate, + IN OUT UINT32 *ReceiveFifoDepth, + IN OUT UINT32 *Timeout, + IN OUT EFI_PARITY_TYPE *Parity, + IN OUT UINT8 *DataBits, + IN OUT EFI_STOP_BITS_TYPE *StopBits + ) +{ + UINT64 SerialClock; + + SerialClock = mPlatformGetClockPpi.PlatformGetClock (NXP_UART_CLOCK, 0); + if (SerialClock == 0) { + return EFI_DEVICE_ERROR; + } + + return PL011UartInitializePort ( + (UINTN)PcdGet64 (PcdSerialRegisterBase), + SerialClock, + BaudRate, + ReceiveFifoDepth, + Parity, + DataBits, + StopBits + ); +} + +/** + + Assert or deassert the control signals on a serial port. + The following control signals are set according their bit settings : + . Request to Send + . Data Terminal Ready + + @param[in] Control The following bits are taken into account : + . EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the + "Request To Send" control signal if this bit is + equal to one/zero. + . EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert + the "Data Terminal Ready" control signal if this + bit is equal to one/zero. + . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable + the hardware loopback if this bit is equal to + one/zero. + . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported. + . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/ + disable the hardware flow control based on CTS (Clear + To Send) and RTS (Ready To Send) control signals. + + @retval RETURN_SUCCESS The new control bits were set on the device. + @retval RETURN_UNSUPPORTED The device does not support this operation. + +**/ +RETURN_STATUS +EFIAPI +SerialPortSetControl ( + IN UINT32 Control + ) +{ + return PL011UartSetControl ((UINTN)PcdGet64 (PcdSerialRegisterBase), Control); +} + +/** + + Retrieve the status of the control bits on a serial device. + + @param[out] Control Status of the control bits on a serial device : + + . EFI_SERIAL_DATA_CLEAR_TO_SEND, + EFI_SERIAL_DATA_SET_READY, + EFI_SERIAL_RING_INDICATE, + EFI_SERIAL_CARRIER_DETECT, + EFI_SERIAL_REQUEST_TO_SEND, + EFI_SERIAL_DATA_TERMINAL_READY + are all related to the DTE (Data Terminal Equipment) + and DCE (Data Communication Equipment) modes of + operation of the serial device. + . EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the + receive buffer is empty, 0 otherwise. + . EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the + transmit buffer is empty, 0 otherwise. + . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if + the hardware loopback is enabled (the output feeds + the receive buffer), 0 otherwise. + . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one + if a loopback is accomplished by software, else 0. + . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to + one if the hardware flow control based on CTS (Clear + To Send) and RTS (Ready To Send) control signals is + enabled, 0 otherwise. + + @retval RETURN_SUCCESS The control bits were read from the device. + +**/ +RETURN_STATUS +EFIAPI +SerialPortGetControl ( + OUT UINT32 *Control + ) +{ + return PL011UartGetControl ((UINTN)PcdGet64 (PcdSerialRegisterBase), Control); +} diff --git a/Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.inf b/Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.inf new file mode 100644 index 0000000000..29f234027f --- /dev/null +++ b/Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.inf @@ -0,0 +1,42 @@ +#/** @file +# +# Component description file for PL011SerialPortLib module +# +# Copyright (c) 2011-2016, ARM Ltd. All rights reserved.
+# Copyright 2020 NXP +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PL011SerialPortLib + FILE_GUID = 8ecefc8f-a2c4-4091-b80f-20f7aeb0567f + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = SerialPortLib + +[Sources.common] + PL011SerialPortLib.c + +[LibraryClasses] + PL011UartLib + PcdLib + ArmPlatformLib + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + Silicon/NXP/NxpQoriqLs.dec + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase + +[FixedPcd] + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits diff --git a/Silicon/NXP/NxpQoriqLs.dsc.inc b/Silicon/NXP/NxpQoriqLs.dsc.inc index 9922686304..2ab6ee1920 100644 --- a/Silicon/NXP/NxpQoriqLs.dsc.inc +++ b/Silicon/NXP/NxpQoriqLs.dsc.inc @@ -100,6 +100,7 @@ IoAccessLib|Silicon/NXP/Library/IoAccessLib/IoAccessLib.inf PlatformPeiLib|Silicon/NXP/Library/PlatformPeiLib/PlatformPeiLib.inf MemoryInitPeiLib|Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf + PL011UartLib|ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.inf [LibraryClasses.common.SEC] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf -- 2.17.1