From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.97545.1671002435405153571 for ; Tue, 13 Dec 2022 23:20:35 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=I9Ai4R9z; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: k.kavyax.sravanthi@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671002434; x=1702538434; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=bASaMIB8n/jJC98V1EnKpu943qFX/aRkecJzQe5LSKU=; b=I9Ai4R9zBubYxVLv+D5kntuAean/RbY56rUgcZXyUktJpO8ivvbqq/bA 5BmH+9vz6kPCulugJqUW37kHfHsgqBgNMNFclwUGPikkhUJSg6bhLh2wl RsF2yaAulTAQ0WTEC/b8UMo3wgMKQmNySj/gyff729tO8updu/jwcZhjh EKeOIMDnI+EZnwPH14NlcwdjxwMnsirbcCgmM+AJnD9+xKxtA1qfpru4Y OK4qjAostSmsp/vNOGFo7fiwn8erUvLEuA2rihfrtR03Ojd64ViZibhZz 8GXfCh7P5+uvPvo9WJ1xOIq2DfJsDIsrCLupyA6htwDFYmWugiQ8b8XIi A==; X-IronPort-AV: E=McAfee;i="6500,9779,10560"; a="382633300" X-IronPort-AV: E=Sophos;i="5.96,243,1665471600"; d="scan'208";a="382633300" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2022 23:20:34 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10560"; a="791202246" X-IronPort-AV: E=Sophos;i="5.96,243,1665471600"; d="scan'208";a="791202246" Received: from ksravanx-mobl.gar.corp.intel.com ([10.215.184.41]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2022 23:20:32 -0800 From: "Kavya" To: devel@edk2.groups.io Cc: Kavya , Guo Dong , Ray Ni , James Lu , Gua Guo Subject: [PATCH] UefiPayloadPkg/SerialPortLib: Enhance multi port behaviour Date: Wed, 14 Dec 2022 12:50:05 +0530 Message-Id: <20221214072005.1133-1-k.kavyax.sravanthi@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add condition to return success if mUartCount is greater than zero in SerialPortInitialize() to avoid filling mUartInfo with the same hob data when SerialPortInitialize() is called multiple times. Also add proper conditions in SerialPortRead function to read the data properly from multiple UART's. Cc: Guo Dong Cc: Ray Ni Cc: James Lu Cc: Gua Guo Signed-off-by: Kavya --- UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c index 809fa2e9c9..84c56bd24d 100644 --- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c +++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c @@ -138,6 +138,10 @@ SerialPortInitialize ( BOOLEAN MmioEnable; UINT8 Value; + if (mUartCount > 0) { + return RETURN_SUCCESS; + } + GuidHob = GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid); while (GuidHob != NULL) { SerialPortInfo = (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *)GET_GUID_HOB_DATA (GuidHob); @@ -329,6 +333,7 @@ SerialPortRead ( { UINTN BaseAddress; BOOLEAN UseMmio; + BOOLEAN IsNextPort; UINT8 *DataBuffer; UINTN BytesLeft; UINTN Result; @@ -353,6 +358,7 @@ SerialPortRead ( DataBuffer = Buffer; BytesLeft = NumberOfBytes; + IsNextPort = FALSE; Mcr = (UINT8)(SerialPortReadRegister (BaseAddress, R_UART_MCR, UseMmio, Stride) & ~B_UART_MCR_RTS); @@ -367,6 +373,12 @@ SerialPortRead ( // SerialPortWriteRegister (BaseAddress, R_UART_MCR, (UINT8)(Mcr | B_UART_MCR_RTS), UseMmio, Stride); } + IsNextPort = TRUE; + break; + } + + if (IsNextPort) { + break; } if (PcdGetBool (PcdSerialUseHardwareFlowControl)) { @@ -382,6 +394,10 @@ SerialPortRead ( *DataBuffer = SerialPortReadRegister (BaseAddress, R_UART_RXBUF, UseMmio, Stride); } + if ((!IsNextPort) && (*(--DataBuffer) != '\0')) { + return Result; + } + Count++; } @@ -409,10 +425,9 @@ SerialPortPoll ( BOOLEAN UseMmio; UINT8 Stride; UINT8 Count; - BOOLEAN Status; + BOOLEAN IsDataReady; Count = 0; - Status = FALSE; while (Count < mUartCount) { BaseAddress = mUartInfo[Count].BaseAddress; UseMmio = mUartInfo[Count].UseMmio; @@ -423,7 +438,7 @@ SerialPortPoll ( continue; } - Status = FALSE; + IsDataReady = FALSE; // // Read the serial port status @@ -436,7 +451,7 @@ SerialPortPoll ( SerialPortWriteRegister (BaseAddress, R_UART_MCR, (UINT8)(SerialPortReadRegister (BaseAddress, R_UART_MCR, UseMmio, Stride) & ~B_UART_MCR_RTS), UseMmio, Stride); } - Status = TRUE; + IsDataReady = TRUE; } if (PcdGetBool (PcdSerialUseHardwareFlowControl)) { @@ -446,10 +461,14 @@ SerialPortPoll ( SerialPortWriteRegister (BaseAddress, R_UART_MCR, (UINT8)(SerialPortReadRegister (BaseAddress, R_UART_MCR, UseMmio, Stride) | B_UART_MCR_RTS), UseMmio, Stride); } + if (IsDataReady) { + return IsDataReady; + } + Count++; } - return Status; + return IsDataReady; } /** @@ -603,6 +622,14 @@ SerialPortGetControl ( *Control |= EFI_SERIAL_INPUT_BUFFER_EMPTY; } + if ((((*Control & EFI_SERIAL_OUTPUT_BUFFER_EMPTY) == EFI_SERIAL_OUTPUT_BUFFER_EMPTY) && + ((*Control & EFI_SERIAL_INPUT_BUFFER_EMPTY) != EFI_SERIAL_INPUT_BUFFER_EMPTY)) || + ((*Control & (EFI_SERIAL_DATA_SET_READY | EFI_SERIAL_CLEAR_TO_SEND | + EFI_SERIAL_CARRIER_DETECT)) == (EFI_SERIAL_DATA_SET_READY | EFI_SERIAL_CLEAR_TO_SEND | + EFI_SERIAL_CARRIER_DETECT))) { + return RETURN_SUCCESS; + } + Count++; } -- 2.30.2.windows.1