From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (EUR04-VI1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.1330.1581060240337512135 for ; Thu, 06 Feb 2020 23:24:02 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nxp.com header.s=selector2 header.b=KnaeUkvG; 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=I5gqxhUfEVQcxthNHfD6PCnWXz5/aMiu58N1p1MRnIBLsSC6ZSW2j1xbpDqcrjzZ1V5fu0TyLkTldo7eYVBT0SbmyTTA2dzPInlPuDrbAOc/qal0JWqvHEPTqZVz5XcvbOa6hgvQEX8dLs1zQDpuwV6rc1AiPmG0bc0LX8uIczM78SUYSAf24T60gK3K168Yw2xsjtklxdIztJym44rZEu1xM/41kRQEU9fSyeOu2WQO2a10p5dRz+ypY9XKyiQttA3tzyIvyd7A5B0kCSPwglwi+Kx/+FjhvYkYZgQGVNH31O7sHEoEUbNNLTRqrnZndCYNLraZekVZZf/uADIB9Q== 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=8CT0rKGxzX90bzUs50zKc1IQfdDkhVBcO14bI74DgHs=; b=TNXtRikns0LNBr0vmsebhBZgvAZIDB2FdPc3uBf+soUydyS36TCgzz7ora1MYKecZeGfGmwVLo9RJh0DRrdeSihLzx2gPDjVQl6Bj3E8GGFryNlubIDT9/vLVjEN7jV+glccCJi4DhG7vah6DPd7Trv2qESNsuIH4wMFbGRBzU0UIki/q8jS8ULZQSNfk+yX2f+renhU0bVNmsFxlW+QatNb3D2h6gCZHU1+nIFQBbojefalHO6USOcr2EACPU9kOw3As5nzghtLVj6FTgDL7RG+aJveqVL/L+0u81feJ1FFTBdUzEzNiijdrXHVXgQmT8xnSewZpIUmuj3NaYo60A== 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=8CT0rKGxzX90bzUs50zKc1IQfdDkhVBcO14bI74DgHs=; b=KnaeUkvGTqfEYMQ9oJz1eR1cfJgJeoAiEO03SIjThEL3zLJkg18O9BKLMPydiVQ5ra0VEKft3uOEp/svjJMiMV2Vhx0QcBuKd9ISQILi1vs1I22IioTYXtvx7lnx2pkA+DJWrFwk2pHVeVgPSUOpNlpwK6ip/m37yQwSJfy7Ktk= 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 VI1PR0401MB2686.eurprd04.prod.outlook.com (10.168.67.146) 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:23:59 +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:23:59 +0000 From: "Pankaj Bansal" To: Leif Lindholm , Meenakshi Aggarwal , Michael D Kinney , Varun Sethi Cc: devel@edk2.groups.io, Pankaj Bansal Subject: [PATCH 05/19] NXP/BaseSerialPortLib16550: remove SerialPortInitalize functionality Date: Fri, 7 Feb 2020 18:13:14 +0530 Message-Id: <20200207124328.8723-6-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:23:57 +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: 35647384-2921-4172-9281-08d7ab9eb2c5 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2686:|VI1PR0401MB2686: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-Forefront-PRVS: 0306EE2ED4 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(136003)(376002)(346002)(39860400002)(366004)(396003)(199004)(189003)(316002)(66556008)(66476007)(66946007)(5660300002)(44832011)(478600001)(2616005)(956004)(4326008)(52116002)(110136005)(26005)(6506007)(16526019)(186003)(1076003)(36756003)(8676002)(6512007)(6636002)(6666004)(19627235002)(81166006)(6486002)(81156014)(2906002)(86362001)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0401MB2686;H:VI1PR0401MB2496.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX: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: SkXcBZayRA2Ja7xlUHZM4vMJR7PRMaThPc88vUetjMJLake7hiqmrxFBz3A4UcBaBrrlVBnQJORHTHjRDRv+6fiA3JCBmg5REknlgHdYmsySUcLVOSysL/XQ1QPqUYMtg1md0LkvRMRCjt3H5BwV84lKpzxoArAm3LPIjLIneTqr8nJgZZuKAZFJWlyslqyNKbA1Vq6GdMrD6gvlCFhM3wGg6jIbXxFTR7JgVHDeT5c86sl29M0c+MuZ/ZcM0KyxVKXEOKM8zzG9ZjbpuCoglugbBKNX9DK5iKpUOHDF+EfdYB/9yc4b3a3FOnePoMKjXGAxVOI1hgY9BgxauuSUgFTrhPetu5fmNIBaJ8jwkzQclwdr4Pw/fD7vYvLVxlDQGhos1ijCxY82NqCEu2IzkvU4XlVhY2hF0/ui9s9AXpW92ivDX9A+pJQf1+FhK04B X-MS-Exchange-AntiSpam-MessageData: bk1LsTtJRQqp8beLMY82TeShA8qOH+ZnHR6zEzrHVnPYg7qw1IqEfyR7bjd9ZE6d8JNDrWhGt1DJoXmh3i50I0O7qvtk2iAYYk8WyL1C0V6u5aC4X/ZpRLF5OiQK1Akv4sWKIiF/sIXVeNnbfxNwGQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 35647384-2921-4172-9281-08d7ab9eb2c5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2020 07:23:59.1708 (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: tiVcGbFQDJuyhTvXdV2cYBOj9piMgSFL6YmJPNTi9rhQII6PsMcW/mIyEwHhLF4+xdDjCU5jk2hPUHj1qgx+1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2686 Content-Type: text/plain SerialPortInitalize is called from DebugLib constructor. so this gets called for each of the module in system. now, during SerialPortInitalize, we need the Uart clock to set it's baud rate. This Uart clock retrieval is implemented in SocLib and it usually involves reading SysClock information (from FPGA or from clock generator) so it's an unnecessary overhead, that can be avoided because we have already initalized SerialPort in SEC phase. Therefore, return SUCCESS from SerialPortInitalize everytime, without doing anything. In SEC phase we use SerialPortSetAttributes with default parameters to mimic SerialPortInitalize. Signed-off-by: Pankaj Bansal --- .../BaseSerialPortLib16550.c | 109 ++++-------------- Silicon/NXP/Library/SocLib/Chassis2/Soc.c | 25 +++- Silicon/NXP/Library/SocLib/LS1043aSocLib.inf | 6 +- 3 files changed, 51 insertions(+), 89 deletions(-) diff --git a/Silicon/NXP/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c b/Silicon/NXP/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c index 2c5c54ac7d..6b2aa46ff6 100644 --- a/Silicon/NXP/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c +++ b/Silicon/NXP/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c @@ -176,92 +176,6 @@ SerialPortInitialize ( VOID ) { - UINTN SerialRegisterBase; - UINT32 Divisor; - UINT32 CurrentDivisor; - BOOLEAN Initialized; - UINT64 SerialClock; - - // - // Perform platform specific initialization required to enable use of the 16550 device - // at the location specified by PcdSerialUseMmio and PcdSerialRegisterBase. - // - SerialClock = GetBusFrequency (); - if (SerialClock == 0) { - return EFI_DEVICE_ERROR; - } - - // - // Calculate divisor for baud generator - // Ref_Clk_Rate / Baud_Rate / 16 - // - Divisor = SerialClock / (PcdGet32 (PcdSerialBaudRate) * 16); - if ((SerialClock % (PcdGet32 (PcdSerialBaudRate) * 16)) >= PcdGet32 (PcdSerialBaudRate) * 8) { - Divisor++; - } - - // - // Get the base address of the serial port in either I/O or MMIO space - // - SerialRegisterBase = GetSerialRegisterBase (); - if (SerialRegisterBase == 0) { - return RETURN_DEVICE_ERROR; - } - - // - // See if the serial port is already initialized - // - Initialized = TRUE; - if ((SerialPortReadRegister (SerialRegisterBase, R_UART_LCR) & 0x3F) != (PcdGet8 (PcdSerialLineControl) & 0x3F)) { - Initialized = FALSE; - } - SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(SerialPortReadRegister (SerialRegisterBase, R_UART_LCR) | B_UART_LCR_DLAB)); - CurrentDivisor = SerialPortReadRegister (SerialRegisterBase, R_UART_BAUD_HIGH) << 8; - CurrentDivisor |= (UINT32) SerialPortReadRegister (SerialRegisterBase, R_UART_BAUD_LOW); - SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(SerialPortReadRegister (SerialRegisterBase, R_UART_LCR) & ~B_UART_LCR_DLAB)); - if (CurrentDivisor != Divisor) { - Initialized = FALSE; - } - if (Initialized) { - return RETURN_SUCCESS; - } - - // - // Wait for the serial port to be ready. - // Verify that both the transmit FIFO and the shift register are empty. - // - while ((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) != (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)); - - // - // Configure baud rate - // - SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, B_UART_LCR_DLAB); - SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_HIGH, (UINT8) (Divisor >> 8)); - SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_LOW, (UINT8) (Divisor & 0xff)); - - // - // Clear DLAB and configure Data Bits, Parity, and Stop Bits. - // Strip reserved bits from PcdSerialLineControl - // - SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(PcdGet8 (PcdSerialLineControl) & 0x3F)); - - // - // Enable and reset FIFOs - // Strip reserved bits from PcdSerialFifoControl - // - SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, 0x00); - SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, (UINT8)(PcdGet8 (PcdSerialFifoControl) & (B_UART_FCR_FIFOE | B_UART_FCR_FIFO64))); - - // - // Set FIFO Polled Mode by clearing IER after setting FCR - // - SerialPortWriteRegister (SerialRegisterBase, R_UART_IER, 0x00); - - // - // Put Modem Control Register(MCR) into its reset state of 0x00. - // - SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, 0x00); - return RETURN_SUCCESS; } @@ -785,6 +699,12 @@ SerialPortSetAttributes ( Divisor++; } + // + // Wait for the serial port to be ready. + // Verify that both the transmit FIFO and the shift register are empty. + // + while ((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) != (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)); + // // Configure baud rate // @@ -799,6 +719,23 @@ SerialPortSetAttributes ( Lcr = (UINT8) ((LcrParity << 3) | (LcrStop << 2) | LcrData); SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8) (Lcr & 0x3F)); + // + // Enable and reset FIFOs + // Strip reserved bits from PcdSerialFifoControl + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, 0x00); + SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, (UINT8)(PcdGet8 (PcdSerialFifoControl) & (B_UART_FCR_FIFOE | B_UART_FCR_FIFO64))); + + // + // Set FIFO Polled Mode by clearing IER after setting FCR + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_IER, 0x00); + + // + // Put Modem Control Register(MCR) into its reset state of 0x00. + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, 0x00); + return RETURN_SUCCESS; } diff --git a/Silicon/NXP/Library/SocLib/Chassis2/Soc.c b/Silicon/NXP/Library/SocLib/Chassis2/Soc.c index bfb8b8cb33..5a1a7376cd 100644 --- a/Silicon/NXP/Library/SocLib/Chassis2/Soc.c +++ b/Silicon/NXP/Library/SocLib/Chassis2/Soc.c @@ -1,7 +1,7 @@ /** @Soc.c SoC specific Library containg functions to initialize various SoC components - Copyright 2017-2019 NXP + Copyright 2017-2020 NXP SPDX-License-Identifier: BSD-2-Clause-Patent @@ -141,12 +141,33 @@ SocInit ( VOID ) { + UINT64 BaudRate; + UINT32 ReceiveFifoDepth; + EFI_PARITY_TYPE Parity; + UINT8 DataBits; + EFI_STOP_BITS_TYPE StopBits; + UINT32 Timeout; + + BaudRate = FixedPcdGet64 (PcdUartDefaultBaudRate); + ReceiveFifoDepth = 0; // Use default FIFO depth + Timeout = 0; + Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity); + DataBits = FixedPcdGet8 (PcdUartDefaultDataBits); + StopBits = (EFI_STOP_BITS_TYPE) FixedPcdGet8 (PcdUartDefaultStopBits); + SmmuInit (); // // Early init serial Port to get board information. // - SerialPortInitialize (); + SerialPortSetAttributes ( + &BaudRate, + &ReceiveFifoDepth, + &Timeout, + &Parity, + &DataBits, + &StopBits + ); DEBUG ((DEBUG_INIT, "\nUEFI firmware (version %s built at %a on %a)\n", (CHAR16*)PcdGetPtr (PcdFirmwareVersionString), __TIME__, __DATE__)); diff --git a/Silicon/NXP/Library/SocLib/LS1043aSocLib.inf b/Silicon/NXP/Library/SocLib/LS1043aSocLib.inf index cb670a1279..3334d4d4f1 100644 --- a/Silicon/NXP/Library/SocLib/LS1043aSocLib.inf +++ b/Silicon/NXP/Library/SocLib/LS1043aSocLib.inf @@ -1,6 +1,6 @@ # @file # -# Copyright 2017-2019 NXP +# Copyright 2017-2020 NXP # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -36,6 +36,10 @@ GCC:*_*_*_CC_FLAGS = -DCHASSIS2 [FixedPcd] + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString gNxpQoriqLsTokenSpaceGuid.PcdClkBaseAddr gNxpQoriqLsTokenSpaceGuid.PcdGurBigEndian -- 2.17.1