From nobody Fri May 3 04:11:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+100646+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+100646+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1677793773; cv=none; d=zohomail.com; s=zohoarc; b=MIMIWlFSZIi1f7URODyB6Wb9hB9ANqfBIp4rxVlzE6DdA8Jop+FZNiEpne783krRhuKFcsf6ABDYPwkUSXWP6+nqwO0rWEcXB3PMmk9T7A0wRyL9M2y25eAAvOvxkXb+2+Q6pdn6rzGTA2gVaMIRDBjfBPDgWHtq/DL8Jx0s2TI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677793773; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=3PTbugItxEiWRmvnocwO9iPp6adVihzB5oWSc/hHPIg=; b=Qi/5wOBr1xidnuGV0lpUCu8kU8B+BYe8/Kqj2x0tLjOI+sB6LV5XpMKlVezS3SXiToPy9hbKyZ3ZeGB1sa6AtAPxxpREzMvEscNcCTBmcxq3dzuyGx6ak9kU5MqPmQraHv8WC4pTX6ScDbNIDVoML9JbY6pQRzPlt7qcj/taE20= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+100646+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1677793773425657.6192098017451; Thu, 2 Mar 2023 13:49:33 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Wk8yYY1788612xETiJfnUAPM; Thu, 02 Mar 2023 13:49:33 -0800 X-Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web10.7580.1677793768526704964 for ; Thu, 02 Mar 2023 13:49:32 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="333584560" X-IronPort-AV: E=Sophos;i="5.98,228,1673942400"; d="scan'208";a="333584560" X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2023 13:49:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="1004321594" X-IronPort-AV: E=Sophos;i="5.98,228,1673942400"; d="scan'208";a="1004321594" X-Received: from mayurkum-mobl2.amr.corp.intel.com (HELO awarkent-mobl1.amr.corp.intel.com) ([10.213.175.186]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2023 13:49:31 -0800 From: "Andrei Warkentin" To: devel@edk2.groups.io Cc: Andrei Warkentin , Daniel Schaefer , Sunil V L , Gerd Hoffmann Subject: [edk2-devel] [edk2 1/3] MdePkg: BaseRiscVSbiLib: make more useful to consumers Date: Thu, 2 Mar 2023 15:49:18 -0600 Message-Id: <20230302214920.13817-2-andrei.warkentin@intel.com> In-Reply-To: <20230302214920.13817-1-andrei.warkentin@intel.com> References: <20230302214920.13817-1-andrei.warkentin@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,andrei.warkentin@intel.com X-Gm-Message-State: 9WpQUrm8p7yxupJwU8hyAWilx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1677793773; bh=kuSv7JCugXIcA9ZhIYFM5roHACmP9bzvvbQddWRjwIo=; h=Cc:Date:From:Reply-To:Subject:To; b=X+a/vkc2t3fZS3AfdM/S5DrhXv+/bCuUE0KOkqk0rfKvX5z2mGN1tI4nMUuuhHFSkLX MQq9nn3xV2e1JsklqTHmdlZDd40tRFwn6VQeaBQFRlu9Y3JNv3pErEIwg8M9yhXQWGX6B UKjrt6k32RIWPcJBTyj2hAGjZFuhvrrzVpM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1677793774867100005 Content-Type: text/plain; charset="utf-8" Add a few more definitions and make SbiCall and TranslateError usable (not static) by library users. Cc: Daniel Schaefer Cc: Sunil V L Acked-by: Gerd Hoffmann Signed-off-by: Andrei Warkentin --- MdePkg/Include/Library/BaseRiscVSbiLib.h | 40 ++++++++++++++++++-- MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c | 3 +- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/MdePkg/Include/Library/BaseRiscVSbiLib.h b/MdePkg/Include/Libr= ary/BaseRiscVSbiLib.h index e75520b4b888..2244165a6b6a 100644 --- a/MdePkg/Include/Library/BaseRiscVSbiLib.h +++ b/MdePkg/Include/Library/BaseRiscVSbiLib.h @@ -2,6 +2,7 @@ Library to call the RISC-V SBI ecalls =20 Copyright (c) 2021-2022, Hewlett Packard Development LP. All rights rese= rved.
+ Copyright (c) 2023, Intel Corporation. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -18,10 +19,28 @@ #include =20 /* SBI Extension IDs */ -#define SBI_EXT_TIME 0x54494D45 -#define SBI_EXT_SRST 0x53525354 +#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 +#define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2 +#define SBI_EXT_BASE 0x10 +#define SBI_EXT_DBCN 0x4442434E +#define SBI_EXT_TIME 0x54494D45 +#define SBI_EXT_SRST 0x53525354 =20 -/* SBI function IDs for TIME extension*/ +/* SBI function IDs for base extension */ +#define SBI_EXT_BASE_SPEC_VERSION 0x0 +#define SBI_EXT_BASE_IMPL_ID 0x1 +#define SBI_EXT_BASE_IMPL_VERSION 0x2 +#define SBI_EXT_BASE_PROBE_EXT 0x3 +#define SBI_EXT_BASE_GET_MVENDORID 0x4 +#define SBI_EXT_BASE_GET_MARCHID 0x5 +#define SBI_EXT_BASE_GET_MIMPID 0x6 + +/* SBI function IDs for DBCN extension */ +#define SBI_EXT_DBCN_WRITE 0x0 +#define SBI_EXT_DBCN_READ 0x1 +#define SBI_EXT_DBCN_WRITE_BYTE 0x2 + +/* SBI function IDs for TIME extension */ #define SBI_EXT_TIME_SET_TIMER 0x0 =20 /* SBI function IDs for SRST extension */ @@ -62,6 +81,21 @@ typedef struct { UINTN Value; ///< Value returned } SBI_RET; =20 +SBI_RET +EFIAPI +SbiCall ( + IN UINTN ExtId, + IN UINTN FuncId, + IN UINTN NumArgs, + ... + ); + +EFI_STATUS +EFIAPI +TranslateError ( + IN UINTN SbiError + ); + VOID EFIAPI SbiSetTimer ( diff --git a/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c b/MdePkg/Libr= ary/BaseRiscVSbiLib/BaseRiscVSbiLib.c index 2ba8f5ed366a..1141abfab9d0 100644 --- a/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c +++ b/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c @@ -4,6 +4,7 @@ It allows calling an SBI function via an ecall from S-Mode. =20 Copyright (c) 2021-2022, Hewlett Packard Development LP. All rights rese= rved.
+ Copyright (c) 2023, Intel Corporation. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -31,7 +32,6 @@ @retval Returns SBI_RET structure with value and error code. =20 **/ -STATIC SBI_RET EFIAPI SbiCall ( @@ -88,7 +88,6 @@ SbiCall ( @param[in] SbiError SBI error code @retval EFI_STATUS **/ -STATIC EFI_STATUS EFIAPI TranslateError ( --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#100646): https://edk2.groups.io/g/devel/message/100646 Mute This Topic: https://groups.io/mt/97349679/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 3 04:11:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+100647+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+100647+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1677793779; cv=none; d=zohomail.com; s=zohoarc; b=OZnq1GslIjELZE+a9mBjQJK8LB0Nfz6j1HgoAVrD5BW3Dre+ayQGvU0d3SbbWNUqGb9bWgJlbfkpbLcS8AB/OrKY71Y0Us745UDtGwF2c9SW2PlNuRgvYDO48OP4hvFVbOJwZPkTsYoRqA2s8vypkGWEPqUSlH2+R7IKMtvtHuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677793779; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=HEn/FpmUztRrP4UnLBgzAYHMcbDpOw72itmDE0SoLIM=; b=K/9agjKXrPk2jaGVf69xkFYfImO7HbVEFUyVXjSkkYHdcGWSqIlBO1+VS7n3h/7gLh2jGDRiei3KrwguM6Y5uilwc6FEl1RMSKXK0Iy4ecwPPLN3w5LIXt2JuCX6wZ66VYo0t7kPwuZ8uA9nl1fismQM4uGR4KataELQIQSpOB0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+100647+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1677793779121736.6376425576096; Thu, 2 Mar 2023 13:49:39 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id w0lSYY1788612xBOTWshx4hr; Thu, 02 Mar 2023 13:49:38 -0800 X-Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web11.7656.1677793777872244982 for ; Thu, 02 Mar 2023 13:49:38 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="333584594" X-IronPort-AV: E=Sophos;i="5.98,228,1673942400"; d="scan'208";a="333584594" X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2023 13:49:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="1004321653" X-IronPort-AV: E=Sophos;i="5.98,228,1673942400"; d="scan'208";a="1004321653" X-Received: from mayurkum-mobl2.amr.corp.intel.com (HELO awarkent-mobl1.amr.corp.intel.com) ([10.213.175.186]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2023 13:49:36 -0800 From: "Andrei Warkentin" To: devel@edk2.groups.io Cc: Andrei Warkentin , Daniel Schaefer , Sunil V L , Gerd Hoffmann Subject: [edk2-devel] [edk2 2/3] [PATCH v2] MdePkg: add SecPeiRiscVSerialPortLibSbi and PrePiDxeRiscVSerialPortLibSbi Date: Thu, 2 Mar 2023 15:49:19 -0600 Message-Id: <20230302214920.13817-3-andrei.warkentin@intel.com> In-Reply-To: <20230302214920.13817-1-andrei.warkentin@intel.com> References: <20230302214920.13817-1-andrei.warkentin@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,andrei.warkentin@intel.com X-Gm-Message-State: hS0BOdyvohSqxqOeBBmA9Obsx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1677793778; bh=Cvr8Pihzk+/rPEJGYCRAvBCaUAa+Tjnb9L84YsxUo0g=; h=Cc:Date:From:Reply-To:Subject:To; b=HIdIS1PAxYt3dKMWjqbydoGcOXAgOFhHBI21B6ppwc7lUo3ER9xtYJHdVHWffM25U9r BGwHgWiQ7xLwWLcXDdUJQov4GUBUoL0mQMOrX2f06Xa177nBSL6mBooqU2X14ZX6BJFIB 6WFFNU3L/hSiKwrjvXWkTqKy+DtUSIFJbuA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1677793780903100001 Content-Type: text/plain; charset="utf-8" These are implementations of SerialPortLib using SBI console services. - SecPeiRiscVSerialPortLibSbi is appropriate for SEC/PEI (XIP) environments - PrePiDxeRiscVSerialPortLibSbi is appropriate for PrePI/DXE environments Tested with: - Qemu RiscVVirt (non-DBCN case, backed by UART) - TinyEMU + RiscVVirt (non-DBCN case, HTIF) - TinyEMU + RiscVVirt (DBCN case, HTIF) Cc: Daniel Schaefer Cc: Sunil V L Acked-by: Gerd Hoffmann Signed-off-by: Andrei Warkentin --- MdePkg/Library/PrePiDxeRiscVSerialPortLibSbi/PrePiDxeRiscVSerialPortLibSbi= .inf | 36 +++ MdePkg/Library/SecPeiRiscVSerialPortLibSbi/SecPeiRiscVSerialPortLibSbi.inf= | 39 +++ MdePkg/Library/PrePiDxeRiscVSerialPortLibSbi/PrePiDxeRiscVSerialPortLibSbi= .c | 264 ++++++++++++++++++++ MdePkg/Library/SecPeiRiscVSerialPortLibSbi/SecPeiRiscVSerialPortLibSbi.c = | 223 +++++++++++++++++ MdePkg/Library/PrePiDxeRiscVSerialPortLibSbi/PrePiDxeRiscVSerialPortLibSbi= .uni | 16 ++ MdePkg/Library/SecPeiRiscVSerialPortLibSbi/SecPeiRiscVSerialPortLibSbi.uni= | 16 ++ 6 files changed, 594 insertions(+) diff --git a/MdePkg/Library/PrePiDxeRiscVSerialPortLibSbi/PrePiDxeRiscVSeri= alPortLibSbi.inf b/MdePkg/Library/PrePiDxeRiscVSerialPortLibSbi/PrePiDxeRis= cVSerialPortLibSbi.inf new file mode 100644 index 000000000000..b25b7e52a31c --- /dev/null +++ b/MdePkg/Library/PrePiDxeRiscVSerialPortLibSbi/PrePiDxeRiscVSerialPortL= ibSbi.inf @@ -0,0 +1,36 @@ +## @file +# Serial Port Library backed by SBI console. +# +# Meant for PrePi and DXE environments (where globals are allowed). See +# SecPeiSerialPortLibRiscVSbi for a reduced variant appropriate for SEC +# and PEI (XIP) environments. +# +# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PrePiDxeRiscVSerialPortLibSbi + MODULE_UNI_FILE =3D PrePiDxeRiscVSerialPortLibSbi.uni + FILE_GUID =3D E4541241-8897-4bba-91F8-7D7E45654346 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SerialPortLib + + +# +# VALID_ARCHITECTURES =3D RISCV64 +# + +[Sources] + PrePiDxeRiscVSerialPortLibSbi.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + RiscVSbiLib diff --git a/MdePkg/Library/SecPeiRiscVSerialPortLibSbi/SecPeiRiscVSerialPo= rtLibSbi.inf b/MdePkg/Library/SecPeiRiscVSerialPortLibSbi/SecPeiRiscVSerial= PortLibSbi.inf new file mode 100644 index 000000000000..249b0a3dcc50 --- /dev/null +++ b/MdePkg/Library/SecPeiRiscVSerialPortLibSbi/SecPeiRiscVSerialPortLibSb= i.inf @@ -0,0 +1,39 @@ +## @file +# Serial Port Library backed by SBI console. +# +# Meant for SEC and PEI (XIP) environments. +# +# Due to limitations of SBI console interface and XIP environments +# (on use of globals), this library instance does not implement reading +# and polling the serial port. See PrePiDxeSerialPortLibRiscVSbi for +# the full-featured variant meant for PrePi and DXE environments. +# +# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SecPeiRiscVSerialPortLibSbi + MODULE_UNI_FILE =3D SecPeiRiscVSerialPortLibSbi.uni + FILE_GUID =3D E4541241-8555-5bba-91F8-7D7E45654346 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SerialPortLib + + +# +# VALID_ARCHITECTURES =3D RISCV64 +# + +[Sources] + SecPeiRiscVSerialPortLibSbi.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + RiscVSbiLib diff --git a/MdePkg/Library/PrePiDxeRiscVSerialPortLibSbi/PrePiDxeRiscVSeri= alPortLibSbi.c b/MdePkg/Library/PrePiDxeRiscVSerialPortLibSbi/PrePiDxeRiscV= SerialPortLibSbi.c new file mode 100644 index 000000000000..12ef43208f59 --- /dev/null +++ b/MdePkg/Library/PrePiDxeRiscVSerialPortLibSbi/PrePiDxeRiscVSerialPortL= ibSbi.c @@ -0,0 +1,264 @@ +/** @file + Serial Port Library backed by SBI console. + + Meant for PrePi and DXE environments (where globals are allowed). See + SecPeiSerialPortLibRiscVSbi for a reduced variant appropriate for SEC + and PEI (XIP) environments. + + Copyright (c) 2023, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +STATIC BOOLEAN mHaveDbcn =3D FALSE; +STATIC INT64 mLastGetChar =3D -1; + +/** + Initialize the serial device hardware. + + If no initialization is required, then return RETURN_SUCCESS. + If the serial device was successfully initialized, then return RETURN_SU= CCESS. + If the serial device could not be initialized, then return RETURN_DEVICE= _ERROR. + + @retval RETURN_SUCCESS The serial device was initialized. + @retval RETURN_DEVICE_ERROR The serial device could not be initialized. + +**/ +RETURN_STATUS +EFIAPI +SerialPortInitialize ( + VOID + ) +{ + SBI_RET Ret; + + Ret =3D SbiCall (SBI_EXT_BASE, SBI_EXT_BASE_PROBE_EXT, 1, SBI_EXT_DBCN); + if ((TranslateError (Ret.Error) =3D=3D EFI_SUCCESS) && + (Ret.Value !=3D 0)) + { + mHaveDbcn =3D TRUE; + } + + return RETURN_SUCCESS; +} + +/** + Write data from buffer to serial device. + + Writes NumberOfBytes data bytes from Buffer to the serial device. + The number of bytes actually written to the serial device is returned. + If the return value is less than NumberOfBytes, then the write operation= failed. + If Buffer is NULL, then ASSERT(). + If NumberOfBytes is zero, then return 0. + + @param Buffer The pointer to the data buffer to be written. + @param NumberOfBytes The number of bytes to written to the serial de= vice. + + @retval 0 NumberOfBytes is 0. + @retval >0 The number of bytes written to the serial devic= e. + If this value is less than NumberOfBytes, then = the write operation failed. + +**/ +UINTN +EFIAPI +SerialPortWrite ( + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + UINTN Index; + + if (mHaveDbcn) { + SBI_RET Ret; + Ret =3D SbiCall ( + SBI_EXT_DBCN, + SBI_EXT_DBCN_WRITE, + 3, + NumberOfBytes, + ((UINTN)Buffer), + 0 + ); + if (TranslateError (Ret.Error) !=3D EFI_SUCCESS) { + return 0; + } + + return Ret.Value; + } + + for (Index =3D 0; Index < NumberOfBytes; Index++) { + SbiCall (SBI_EXT_0_1_CONSOLE_PUTCHAR, 0, 1, Buffer[Index]); + } + + return Index; +} + +/** + Read data from serial device and save the datas in buffer. + + Reads NumberOfBytes data bytes from a serial device into the buffer + specified by Buffer. The number of bytes actually read is returned. + If the return value is less than NumberOfBytes, then the rest operation = failed. + If Buffer is NULL, then ASSERT(). + If NumberOfBytes is zero, then return 0. + + @param Buffer The pointer to the data buffer to store the dat= a read from the serial device. + @param NumberOfBytes The number of bytes which will be read. + + @retval 0 Read data failed; No data is to be read. + @retval >0 The actual number of bytes read from serial dev= ice. + +**/ +UINTN +EFIAPI +SerialPortRead ( + OUT UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + UINTN Index =3D 0; + + while ((Index < NumberOfBytes) && SerialPortPoll ()) { + Buffer[Index++] =3D (UINT8)mLastGetChar; + mLastGetChar =3D -1; + } + + return Index; +} + +/** + Polls a serial device to see if there is any data waiting to be read. + + Polls a serial device to see if there is any data waiting to be read. + If there is data waiting to be read from the serial device, then TRUE is= returned. + If there is no data waiting to be read from the serial device, then FALS= E is returned. + + @retval TRUE Data is waiting to be read from the serial devi= ce. + @retval FALSE There is no data waiting to be read from the se= rial device. + +**/ +BOOLEAN +EFIAPI +SerialPortPoll ( + VOID + ) +{ + /* + * Careful. OpenSBI with HTIF console will return -1 followed by -2 + * if there is no character received. So just check for values >=3D 0. + */ + + if (mLastGetChar >=3D 0) { + return TRUE; + } + + if (mHaveDbcn) { + UINT8 Buffer; + SBI_RET Ret =3D SbiCall ( + SBI_EXT_DBCN, + SBI_EXT_DBCN_READ, + 3, + 1, + ((UINTN)&Buffer), + 0 + ); + if ((TranslateError (Ret.Error) =3D=3D EFI_SUCCESS) && + (Ret.Value =3D=3D 1)) + { + mLastGetChar =3D Buffer; + } + } else { + mLastGetChar =3D (INT64)SbiCall (SBI_EXT_0_1_CONSOLE_GETCHAR, 0, 0).Er= ror; + } + + return mLastGetChar >=3D 0; +} + +/** + Sets the control bits on a serial device. + + @param Control Sets the bits of Control that are settable. + + @retval RETURN_SUCCESS The new control bits were set on the seria= l device. + @retval RETURN_UNSUPPORTED The serial device does not support this op= eration. + @retval RETURN_DEVICE_ERROR The serial device is not functioning corre= ctly. + +**/ +RETURN_STATUS +EFIAPI +SerialPortSetControl ( + IN UINT32 Control + ) +{ + return RETURN_SUCCESS; +} + +/** + Retrieve the status of the control bits on a serial device. + + @param Control A pointer to return the current control si= gnals from the serial device. + + @retval RETURN_SUCCESS The control bits were read from the serial= device. + @retval RETURN_UNSUPPORTED The serial device does not support this op= eration. + @retval RETURN_DEVICE_ERROR The serial device is not functioning corre= ctly. + +**/ +RETURN_STATUS +EFIAPI +SerialPortGetControl ( + OUT UINT32 *Control + ) +{ + *Control =3D 0; + return RETURN_SUCCESS; +} + +/** + Sets the baud rate, receive FIFO depth, transmit/receice time out, parit= y, + data bits, and stop bits on a serial device. + + @param BaudRate The requested baud rate. A BaudRate value of 0= will use the + device's default interface speed. + On output, the value actually set. + @param ReveiveFifoDepth The requested depth of the FIFO on the receive= side of the + serial interface. A ReceiveFifoDepth value of = 0 will use + the device's default FIFO depth. + On output, the value actually set. + @param Timeout The requested time out for a single character = in microseconds. + This timeout applies to both the transmit and = receive side of the + interface. A Timeout value of 0 will use the d= evice's default time + out value. + On output, the value actually set. + @param Parity The type of parity to use on this serial devic= e. A Parity value of + DefaultParity will use the device's default pa= rity value. + On output, the value actually set. + @param DataBits The number of data bits to use on the serial d= evice. A DataBits + vaule of 0 will use the device's default data = bit setting. + On output, the value actually set. + @param StopBits The number of stop bits to use on this serial = device. A StopBits + value of DefaultStopBits will use the device's= default number of + stop bits. + On output, the value actually set. + + @retval RETURN_SUCCESS The new attributes were set on the ser= ial device. + @retval RETURN_UNSUPPORTED The serial device does not support thi= s operation. + @retval RETURN_INVALID_PARAMETER One or more of the attributes has an u= nsupported value. + @retval RETURN_DEVICE_ERROR The serial device is not functioning c= orrectly. + +**/ +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 + ) +{ + return RETURN_SUCCESS; +} diff --git a/MdePkg/Library/SecPeiRiscVSerialPortLibSbi/SecPeiRiscVSerialPo= rtLibSbi.c b/MdePkg/Library/SecPeiRiscVSerialPortLibSbi/SecPeiRiscVSerialPo= rtLibSbi.c new file mode 100644 index 000000000000..68e95db44692 --- /dev/null +++ b/MdePkg/Library/SecPeiRiscVSerialPortLibSbi/SecPeiRiscVSerialPortLibSb= i.c @@ -0,0 +1,223 @@ +/** @file + Serial Port Library backed by SBI console. + + Meant for SEC and PEI (XIP) environments. + + Due to limitations of SBI console interface and XIP environments + (on use of globals), this library instance does not implement reading + and polling the serial port. See PrePiDxeSerialPortLibRiscVSbi for + the full-featured variant meant for PrePi and DXE environments. + + Copyright (c) 2023, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +/** + Initialize the serial device hardware. + + If no initialization is required, then return RETURN_SUCCESS. + If the serial device was successfully initialized, then return RETURN_SU= CCESS. + If the serial device could not be initialized, then return RETURN_DEVICE= _ERROR. + + @retval RETURN_SUCCESS The serial device was initialized. + @retval RETURN_DEVICE_ERROR The serial device could not be initialized. + +**/ +RETURN_STATUS +EFIAPI +SerialPortInitialize ( + VOID + ) +{ + return RETURN_SUCCESS; +} + +/** + Write data from buffer to serial device. + + Writes NumberOfBytes data bytes from Buffer to the serial device. + The number of bytes actually written to the serial device is returned. + If the return value is less than NumberOfBytes, then the write operation= failed. + If Buffer is NULL, then ASSERT(). + If NumberOfBytes is zero, then return 0. + + @param Buffer The pointer to the data buffer to be written. + @param NumberOfBytes The number of bytes to written to the serial de= vice. + + @retval 0 NumberOfBytes is 0. + @retval >0 The number of bytes written to the serial devic= e. + If this value is less than NumberOfBytes, then = the write operation failed. + +**/ +UINTN +EFIAPI +SerialPortWrite ( + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + SBI_RET Ret; + UINTN Index; + + Ret =3D SbiCall (SBI_EXT_BASE, SBI_EXT_BASE_PROBE_EXT, 1, SBI_EXT_DBCN); + if ((TranslateError (Ret.Error) =3D=3D EFI_SUCCESS) && + (Ret.Value !=3D 0)) + { + Ret =3D SbiCall ( + SBI_EXT_DBCN, + SBI_EXT_DBCN_WRITE, + 3, + NumberOfBytes, + ((UINTN)Buffer), + 0 + ); + if (TranslateError (Ret.Error) !=3D EFI_SUCCESS) { + return 0; + } + + return Ret.Value; + } + + for (Index =3D 0; Index < NumberOfBytes; Index++) { + SbiCall (SBI_EXT_0_1_CONSOLE_PUTCHAR, 0, 1, Buffer[Index]); + } + + return Index; +} + +/** + Read data from serial device and save the datas in buffer. + + Reads NumberOfBytes data bytes from a serial device into the buffer + specified by Buffer. The number of bytes actually read is returned. + If the return value is less than NumberOfBytes, then the rest operation = failed. + If Buffer is NULL, then ASSERT(). + If NumberOfBytes is zero, then return 0. + + @param Buffer The pointer to the data buffer to store the dat= a read from the serial device. + @param NumberOfBytes The number of bytes which will be read. + + @retval 0 Read data failed; No data is to be read. + @retval >0 The actual number of bytes read from serial dev= ice. + +**/ +UINTN +EFIAPI +SerialPortRead ( + OUT UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + return 0; +} + +/** + Polls a serial device to see if there is any data waiting to be read. + + Polls a serial device to see if there is any data waiting to be read. + If there is data waiting to be read from the serial device, then TRUE is= returned. + If there is no data waiting to be read from the serial device, then FALS= E is returned. + + @retval TRUE Data is waiting to be read from the serial devi= ce. + @retval FALSE There is no data waiting to be read from the se= rial device. + +**/ +BOOLEAN +EFIAPI +SerialPortPoll ( + VOID + ) +{ + return FALSE; +} + +/** + Sets the control bits on a serial device. + + @param Control Sets the bits of Control that are settable. + + @retval RETURN_SUCCESS The new control bits were set on the seria= l device. + @retval RETURN_UNSUPPORTED The serial device does not support this op= eration. + @retval RETURN_DEVICE_ERROR The serial device is not functioning corre= ctly. + +**/ +RETURN_STATUS +EFIAPI +SerialPortSetControl ( + IN UINT32 Control + ) +{ + return RETURN_SUCCESS; +} + +/** + Retrieve the status of the control bits on a serial device. + + @param Control A pointer to return the current control si= gnals from the serial device. + + @retval RETURN_SUCCESS The control bits were read from the serial= device. + @retval RETURN_UNSUPPORTED The serial device does not support this op= eration. + @retval RETURN_DEVICE_ERROR The serial device is not functioning corre= ctly. + +**/ +RETURN_STATUS +EFIAPI +SerialPortGetControl ( + OUT UINT32 *Control + ) +{ + *Control =3D 0; + return RETURN_SUCCESS; +} + +/** + Sets the baud rate, receive FIFO depth, transmit/receice time out, parit= y, + data bits, and stop bits on a serial device. + + @param BaudRate The requested baud rate. A BaudRate value of 0= will use the + device's default interface speed. + On output, the value actually set. + @param ReveiveFifoDepth The requested depth of the FIFO on the receive= side of the + serial interface. A ReceiveFifoDepth value of = 0 will use + the device's default FIFO depth. + On output, the value actually set. + @param Timeout The requested time out for a single character = in microseconds. + This timeout applies to both the transmit and = receive side of the + interface. A Timeout value of 0 will use the d= evice's default time + out value. + On output, the value actually set. + @param Parity The type of parity to use on this serial devic= e. A Parity value of + DefaultParity will use the device's default pa= rity value. + On output, the value actually set. + @param DataBits The number of data bits to use on the serial d= evice. A DataBits + vaule of 0 will use the device's default data = bit setting. + On output, the value actually set. + @param StopBits The number of stop bits to use on this serial = device. A StopBits + value of DefaultStopBits will use the device's= default number of + stop bits. + On output, the value actually set. + + @retval RETURN_SUCCESS The new attributes were set on the ser= ial device. + @retval RETURN_UNSUPPORTED The serial device does not support thi= s operation. + @retval RETURN_INVALID_PARAMETER One or more of the attributes has an u= nsupported value. + @retval RETURN_DEVICE_ERROR The serial device is not functioning c= orrectly. + +**/ +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 + ) +{ + return RETURN_SUCCESS; +} diff --git a/MdePkg/Library/PrePiDxeRiscVSerialPortLibSbi/PrePiDxeRiscVSeri= alPortLibSbi.uni b/MdePkg/Library/PrePiDxeRiscVSerialPortLibSbi/PrePiDxeRis= cVSerialPortLibSbi.uni new file mode 100644 index 000000000000..7b22caa5a090 --- /dev/null +++ b/MdePkg/Library/PrePiDxeRiscVSerialPortLibSbi/PrePiDxeRiscVSerialPortL= ibSbi.uni @@ -0,0 +1,16 @@ +// /** @file +// Serial Port Library backed by SBI console. +// +// Serial Port Library backed by SBI console. +// +// Copyright (c) 2023, Intel Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Serial Port Libra= ry backed by SBI console" + +#string STR_MODULE_DESCRIPTION #language en-US "Serial Port Libra= ry backed by SBI console." + diff --git a/MdePkg/Library/SecPeiRiscVSerialPortLibSbi/SecPeiRiscVSerialPo= rtLibSbi.uni b/MdePkg/Library/SecPeiRiscVSerialPortLibSbi/SecPeiRiscVSerial= PortLibSbi.uni new file mode 100644 index 000000000000..7b22caa5a090 --- /dev/null +++ b/MdePkg/Library/SecPeiRiscVSerialPortLibSbi/SecPeiRiscVSerialPortLibSb= i.uni @@ -0,0 +1,16 @@ +// /** @file +// Serial Port Library backed by SBI console. +// +// Serial Port Library backed by SBI console. +// +// Copyright (c) 2023, Intel Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Serial Port Libra= ry backed by SBI console" + +#string STR_MODULE_DESCRIPTION #language en-US "Serial Port Libra= ry backed by SBI console." + --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#100647): https://edk2.groups.io/g/devel/message/100647 Mute This Topic: https://groups.io/mt/97349687/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 3 04:11:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+100648+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+100648+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1677793783; cv=none; d=zohomail.com; s=zohoarc; b=kiLL8lpEOL8W7NgZqBi4Am3SJAIUWfTL16KOdVoa98DN6OYnmvx/bFja4QsLrOEK6CwkOWHogdG02k9ibDG7l2I0O3NU61MEHeCv/Ch4eZMQeiBUg0s88i72vFV6Edk7zyTl/PgxVBiRB11mE0U83BVNd1W99Is+BfPH6Ijki9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677793783; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=EJ44Wyg305RDu6p2sKFXuI6z0beHASKHAB69irbbaxs=; b=bmDo65SqEkwUPWEw3oRt3tel7rzhCz3PSvY9bsw9iwwBblrxZH9+Pz3w6vdoa4ReucpgHK7uk9LYQf4Ogct0W9TIILDUDbIwpP8OER1HrbTWP98KoE2a4nr0XpTULPwfYoUjGolDIMHZdXTQf79yXe7l7JDz8HY43ThegZ99/uY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+100648+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1677793783610914.5082273302497; Thu, 2 Mar 2023 13:49:43 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id XUc3YY1788612xrFvFkJTs9v; Thu, 02 Mar 2023 13:49:43 -0800 X-Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web11.7656.1677793777872244982 for ; Thu, 02 Mar 2023 13:49:42 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="333584620" X-IronPort-AV: E=Sophos;i="5.98,228,1673942400"; d="scan'208";a="333584620" X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2023 13:49:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="1004321708" X-IronPort-AV: E=Sophos;i="5.98,228,1673942400"; d="scan'208";a="1004321708" X-Received: from mayurkum-mobl2.amr.corp.intel.com (HELO awarkent-mobl1.amr.corp.intel.com) ([10.213.175.186]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2023 13:49:41 -0800 From: "Andrei Warkentin" To: devel@edk2.groups.io Cc: Andrei Warkentin , Daniel Schaefer , Sunil V L Subject: [edk2-devel] [edk2 3/3] OvmfPkg: RiscVVirt: Add missing SerialPortInitialize to Sec Date: Thu, 2 Mar 2023 15:49:20 -0600 Message-Id: <20230302214920.13817-4-andrei.warkentin@intel.com> In-Reply-To: <20230302214920.13817-1-andrei.warkentin@intel.com> References: <20230302214920.13817-1-andrei.warkentin@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,andrei.warkentin@intel.com X-Gm-Message-State: KuWfUchXv4LqWOjeiOccpF2sx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1677793783; bh=j780TnFKxXAZLt2iIa5rrvFC71481yBCoVIG9fS4lf8=; h=Cc:Date:From:Reply-To:Subject:To; b=paH3vuR9p6UdZ4wn2ZYF7hB7zQMn1+7jnpn70fU0Be1jSCz5xVmrsfJCNkO2BiazUIl WJ+18hqLw+TSuTGnoDFQrkeZqAv7GPzq4QjyQmgn5hmjvnRJn7DHRB3cuhlcqXg+KvK/b x7BJ2GxSxePirK20Fu8T0iCOmKnXLuzgKd8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1677793784948100001 Content-Type: text/plain; charset="utf-8" If the SerialPortLib had any initialization needed, this would be skipped in the RiscVVirt Sec. Follow the example seen elsewhere (ArmVirtPkg PrePi). Seen with BaseSerialPortLibRiscVSbi not using DBCN in Sec, yet using DBCN elsewhere. Cc: Daniel Schaefer Cc: Sunil V L Signed-off-by: Andrei Warkentin --- OvmfPkg/RiscVVirt/Sec/SecMain.inf | 1 + OvmfPkg/RiscVVirt/Sec/SecMain.h | 1 + OvmfPkg/RiscVVirt/Sec/SecMain.c | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/RiscVVirt/Sec/SecMain.inf b/OvmfPkg/RiscVVirt/Sec/SecM= ain.inf index aed35d3af596..0e2a5785e8a4 100644 --- a/OvmfPkg/RiscVVirt/Sec/SecMain.inf +++ b/OvmfPkg/RiscVVirt/Sec/SecMain.inf @@ -48,6 +48,7 @@ [LibraryClasses] FdtLib MemoryAllocationLib HobLib + SerialPortLib =20 [Ppis] gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED diff --git a/OvmfPkg/RiscVVirt/Sec/SecMain.h b/OvmfPkg/RiscVVirt/Sec/SecMai= n.h index 83a8058efe40..7c7650f0d298 100644 --- a/OvmfPkg/RiscVVirt/Sec/SecMain.h +++ b/OvmfPkg/RiscVVirt/Sec/SecMain.h @@ -29,6 +29,7 @@ #include #include #include +#include #include =20 /** diff --git a/OvmfPkg/RiscVVirt/Sec/SecMain.c b/OvmfPkg/RiscVVirt/Sec/SecMai= n.c index adf73f2eb66c..db309ebdf1a3 100644 --- a/OvmfPkg/RiscVVirt/Sec/SecMain.c +++ b/OvmfPkg/RiscVVirt/Sec/SecMain.c @@ -1,7 +1,7 @@ /** @file RISC-V SEC phase module for Qemu Virt. =20 - Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.
Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -57,6 +57,8 @@ SecStartup ( UINT64 StackBase; UINT32 StackSize; =20 + SerialPortInitialize (); + // // Report Status Code to indicate entering SEC core // --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#100648): https://edk2.groups.io/g/devel/message/100648 Mute This Topic: https://groups.io/mt/97349688/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-