From nobody Sun May 19 00:47:56 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+105340+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+105340+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1685143062; cv=none; d=zohomail.com; s=zohoarc; b=aMF6GlLzVOeHlSNrT0wfftM5023vQAsiG8SaY7uHAry+LNRPxJZcun83LSDhV51v/21/vrTYoimIcH4a2hcf8UoIhvhMOJoaBs8nEJRgoakYfwYPj6DL2WzRD4iaZGTc2JHcG+dsAxiICpNQ8Te783uw6Jp3hbtRAedTqLmuPQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685143062; 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=jSOuq7hWpOe+V91tz2n7A85Knt8QXJBIrCEHdjC8WTs=; b=nZXTitusweF3d6V5jVmcqhLDpsV3ifAU1oFOK4T0hTKTBl3+LbGpVM516IaC9eKj5hqSBA7X+NyQ99N8oZFfrKEISqfW8xjNI7TwLA/oFqgOjTiozUn2l76Mc6T/VqOcJy9Cb8ie9R7GHWxHCMBJUSnJAxBvWYx2m7rk26oFzpo= 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+105340+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685143062773843.9396239800003; Fri, 26 May 2023 16:17:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id olteYY1788612xREWY4fmzNw; Fri, 26 May 2023 16:17:42 -0700 X-Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by mx.groups.io with SMTP id smtpd.web11.1174.1685143061727830684 for ; Fri, 26 May 2023 16:17:41 -0700 X-Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-64f47448aeaso1136036b3a.0 for ; Fri, 26 May 2023 16:17:41 -0700 (PDT) X-Gm-Message-State: 2x6hPvSVyZ3AzDZogN58TTWMx1787277AA= X-Google-Smtp-Source: ACHHUZ6xRbX14886MMZvM8E2alJmB79y+J+/6RS0/WpAt8dHiMgjVX3Y5D8/kcUIz+IRm8/20LKGcg== X-Received: by 2002:a05:6a21:78a4:b0:10f:f672:6e88 with SMTP id bf36-20020a056a2178a400b0010ff6726e88mr1359381pzc.4.1685143060850; Fri, 26 May 2023 16:17:40 -0700 (PDT) X-Received: from localhost.localdomain (c-174-50-177-95.hsd1.ca.comcast.net. [174.50.177.95]) by smtp.gmail.com with ESMTPSA id k3-20020aa792c3000000b005d22639b577sm3106308pfa.165.2023.05.26.16.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 16:17:40 -0700 (PDT) From: "Tuan Phan" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, gaoliming@byosoft.com.cn, zhiguang.liu@intel.com, sunilvl@ventanamicro.com, git@danielschaefer.me, andrei.warkentin@intel.com, Tuan Phan Subject: [edk2-devel] [PATCH v3 1/7] MdePkg/BaseLib: RISC-V: Support getting satp register value Date: Fri, 26 May 2023 16:17:27 -0700 Message-Id: <20230526231733.6755-2-tphan@ventanamicro.com> In-Reply-To: <20230526231733.6755-1-tphan@ventanamicro.com> References: <20230526231733.6755-1-tphan@ventanamicro.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,tphan@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685143062; bh=P2A3r6Apt0muIpGXwipBt18RAk2C6tCtSIPLOXApM/s=; h=Cc:Date:From:Reply-To:Subject:To; b=d6A8M/kz631JSBR8besxbNI8gJHpBxK083nRUwny9abV6Cyz/JOYXDRq2WMU66sMhv2 Yu+N70+8D2KRw7DUQQVZ+0JpwKXUY5jco0b6z9F1HlgL3v0lDu12E0Pv9hS7F4gh+tFiy k7F7KRyvLRuZ2U1pBWbUVx0CvCN4Ex/oEMQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685143063267100004 Content-Type: text/plain; charset="utf-8" Add an API to retrieve satp register value. Signed-off-by: Tuan Phan Reviewed-by: Andrei Warkentin Reviewed-by: Sunil V L --- MdePkg/Include/Library/BaseLib.h | 5 +++++ MdePkg/Library/BaseLib/RiscV64/RiscVMmu.S | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 8f2df76c29a3..5d7067ee854e 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -181,6 +181,11 @@ RiscVSetSupervisorAddressTranslationRegister ( IN UINT64 ); =20 +UINT64 +RiscVGetSupervisorAddressTranslationRegister ( + VOID + ); + UINT64 RiscVReadTimer ( VOID diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVMmu.S b/MdePkg/Library/Bas= eLib/RiscV64/RiscVMmu.S index ac8f92f38aed..c9cf60c1664b 100644 --- a/MdePkg/Library/BaseLib/RiscV64/RiscVMmu.S +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVMmu.S @@ -21,3 +21,11 @@ ASM_FUNC (RiscVSetSupervisorAddressTranslationRegister) csrw CSR_SATP, a0 ret + +// +// Get the value of Supervisor Address Translation and +// Protection Register. +// +ASM_FUNC (RiscVGetSupervisorAddressTranslationRegister) + csrr a0, CSR_SATP + ret --=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 (#105340): https://edk2.groups.io/g/devel/message/105340 Mute This Topic: https://groups.io/mt/99159993/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 Sun May 19 00:47:56 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+105341+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+105341+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1685143063; cv=none; d=zohomail.com; s=zohoarc; b=UXBcT5t1RruxE03HTUv6LjvMi+q/BQ2VJjpm//UwPmCX/gXMLEB5mKKiSjp5MpB13dwr/nZcm71moNCuppd89TAIIZuoGboRJVhAYhiLgVVwYV29lswSGdToV0Oiu10tYVKtE+u2CXT5XFDM9Ab2kl8N5Lrsx77d/u0RL2BWYeQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685143063; 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=XDjbgbkdalL6h55E/L4sgulXTs3sPwnsE8Qee8R5iRU=; b=HWQe8WOJgMM5JYeSw0Ysre3pOfZuwcSobnCGJ4ZGBLCvmMZTma+9ZO8zmFiwwb2VsvEl87aVuRbVKvT5aBwbhue8seqPsrdmUbmlSuEQPBVV1uM+KotH/gdbJYlxWd2nVOkLj0nSAUTXJbSiUNdCuGYlublU9GiSGKiO7MoME0Q= 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+105341+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685143063741689.2252199483466; Fri, 26 May 2023 16:17:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qhWIYY1788612xJnIzGvJIWO; Fri, 26 May 2023 16:17:43 -0700 X-Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mx.groups.io with SMTP id smtpd.web10.1083.1685143062920599913 for ; Fri, 26 May 2023 16:17:42 -0700 X-Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-64d577071a6so1791016b3a.1 for ; Fri, 26 May 2023 16:17:42 -0700 (PDT) X-Gm-Message-State: u2vgo95mlkNsb0lgZwMNLqDYx1787277AA= X-Google-Smtp-Source: ACHHUZ7hz4B5XvWh99Ubq478w6Ytqw3okncJYjFVGH75mr79yV/n0SItKbshQtRRI/lc1E1W+kCmbQ== X-Received: by 2002:a05:6a20:7d88:b0:10c:29e5:941e with SMTP id v8-20020a056a207d8800b0010c29e5941emr1096765pzj.59.1685143062108; Fri, 26 May 2023 16:17:42 -0700 (PDT) X-Received: from localhost.localdomain (c-174-50-177-95.hsd1.ca.comcast.net. [174.50.177.95]) by smtp.gmail.com with ESMTPSA id k3-20020aa792c3000000b005d22639b577sm3106308pfa.165.2023.05.26.16.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 16:17:41 -0700 (PDT) From: "Tuan Phan" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, gaoliming@byosoft.com.cn, zhiguang.liu@intel.com, sunilvl@ventanamicro.com, git@danielschaefer.me, andrei.warkentin@intel.com, Tuan Phan Subject: [edk2-devel] [PATCH v3 2/7] MdePkg/Register: RISC-V: Add satp mode bits shift definition Date: Fri, 26 May 2023 16:17:28 -0700 Message-Id: <20230526231733.6755-3-tphan@ventanamicro.com> In-Reply-To: <20230526231733.6755-1-tphan@ventanamicro.com> References: <20230526231733.6755-1-tphan@ventanamicro.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,tphan@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685143063; bh=pCB3uT3IGF9HPTFZIAUmpek4KAKlKJerWNeu/7vlixE=; h=Cc:Date:From:Reply-To:Subject:To; b=rEAW6gDlnDJe8dePntHK3jJUFo6+ARSrj0tAi4lnigCVLHsSNEjNKNHMS9+HDCMDzGm aNea7GuPYxRs3j4VVIFp8oGUZPhuyjO6Huw4GdNZhf7IdGc8Kx10Z8SBjtWQz+c9YlOEl nFDEX8W1ftIjRONpEByTP7x1hbpIr+sBVvE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685143064429100009 Content-Type: text/plain; charset="utf-8" The satp mode bits shift is used cross modules. It should be defined in one place. Signed-off-by: Tuan Phan Reviewed-by: Andrei Warkentin Reviewed-by: Sunil V L --- MdePkg/Include/Register/RiscV64/RiscVEncoding.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MdePkg/Include/Register/RiscV64/RiscVEncoding.h b/MdePkg/Inclu= de/Register/RiscV64/RiscVEncoding.h index 5c2989b797bf..2bde8db478ff 100644 --- a/MdePkg/Include/Register/RiscV64/RiscVEncoding.h +++ b/MdePkg/Include/Register/RiscV64/RiscVEncoding.h @@ -58,9 +58,10 @@ #define PRV_S 1UL #define PRV_M 3UL =20 -#define SATP64_MODE 0xF000000000000000ULL -#define SATP64_ASID 0x0FFFF00000000000ULL -#define SATP64_PPN 0x00000FFFFFFFFFFFULL +#define SATP64_MODE 0xF000000000000000ULL +#define SATP64_MODE_SHIFT 60 +#define SATP64_ASID 0x0FFFF00000000000ULL +#define SATP64_PPN 0x00000FFFFFFFFFFFULL =20 #define SATP_MODE_OFF 0UL #define SATP_MODE_SV32 1UL --=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 (#105341): https://edk2.groups.io/g/devel/message/105341 Mute This Topic: https://groups.io/mt/99159995/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 Sun May 19 00:47:56 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+105342+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+105342+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1685143065; cv=none; d=zohomail.com; s=zohoarc; b=aF5v0Uz2ASvwu5cVB07cfFJmxha+whie1owv81np+GQygQ9xiu9LUCinTDtyCoEeztn0UjnNpEiETppLb+cUTDKyasnw8C4i9qwtEjq3T9j6qaKGCMBXX3tzNkyoZCcbKBLwWX3liiWuSUl/EDBc1SKNHkwmBgYLmZEwgAflqZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685143065; 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=RWXg4G9vpu9ouiF2G0Qi2Qpe5An6x8zHPNIEq1ezSIw=; b=aTyO8ecXxqARox9HfBmNZ4BnvNAjTDqkj5ywLm+JWDOMCNCjdOcfcWKnhL9FHwvlcepWLUrMtIKsjcMz6s1ISC3eeyZzCySEoL1itW9paOVzApy22oAAjTAPonPphcWTgDHqLLT1sklXJioZTunPBwnrpDkHtNZbpf+YKH6AJCM= 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+105342+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 168514306552952.05171438188938; Fri, 26 May 2023 16:17:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 191zYY1788612xBELGMOM8wK; Fri, 26 May 2023 16:17:45 -0700 X-Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mx.groups.io with SMTP id smtpd.web10.1085.1685143064561239794 for ; Fri, 26 May 2023 16:17:44 -0700 X-Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-64d3491609fso1146465b3a.3 for ; Fri, 26 May 2023 16:17:44 -0700 (PDT) X-Gm-Message-State: eBy1ZfYCCK0506qfg37LrR6dx1787277AA= X-Google-Smtp-Source: ACHHUZ6Vjnl8MoNNA3I457O6CCWGur5/iQJTCFNS1GYR7RFWOBKDaAmO0Qlmnw+sctwkuLvyVUG7RA== X-Received: by 2002:a05:6a21:6710:b0:10b:8e96:561 with SMTP id wh16-20020a056a21671000b0010b8e960561mr774248pzb.62.1685143063457; Fri, 26 May 2023 16:17:43 -0700 (PDT) X-Received: from localhost.localdomain (c-174-50-177-95.hsd1.ca.comcast.net. [174.50.177.95]) by smtp.gmail.com with ESMTPSA id k3-20020aa792c3000000b005d22639b577sm3106308pfa.165.2023.05.26.16.17.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 16:17:43 -0700 (PDT) From: "Tuan Phan" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, gaoliming@byosoft.com.cn, zhiguang.liu@intel.com, sunilvl@ventanamicro.com, git@danielschaefer.me, andrei.warkentin@intel.com, Tuan Phan Subject: [edk2-devel] [PATCH v3 3/7] UefiCpuPkg: RISC-V: Support MMU with SV39/48/57 mode Date: Fri, 26 May 2023 16:17:29 -0700 Message-Id: <20230526231733.6755-4-tphan@ventanamicro.com> In-Reply-To: <20230526231733.6755-1-tphan@ventanamicro.com> References: <20230526231733.6755-1-tphan@ventanamicro.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,tphan@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685143065; bh=ccuEfaCsZqUOTVg25hCQ+3RmtJ1sz/C5kJ5G97YpKrY=; h=Cc:Date:From:Reply-To:Subject:To; b=bIwNOo1eoL/bcCJEzNFHEBxvdmN5Olgue99q38ZY8v6UXKJvlLRmIxlnqFwVpE6GI8Z DR6YctVhnFpe5Pa3ykkn4pzbwuZfXYblPorM2uuXlTNbfJmxDDdbhA/AKHzz1fqpme/rl S7KUn28boXvxk8j9NZi1d+kOqEOGYY070TY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685143067268100016 Content-Type: text/plain; charset="utf-8" During CpuDxe initialization, MMU will be setup with the highest mode that HW supports. Signed-off-by: Tuan Phan Reviewed-by: Andrei Warkentin --- UefiCpuPkg/CpuDxeRiscV64/CpuDxe.c | 9 +- UefiCpuPkg/CpuDxeRiscV64/CpuDxe.h | 2 + UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf | 2 + UefiCpuPkg/Include/Library/BaseRiscVMmuLib.h | 39 ++ .../Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c | 569 ++++++++++++++++++ .../BaseRiscVMmuLib/BaseRiscVMmuLib.inf | 26 + .../Library/BaseRiscVMmuLib/RiscVMmuCore.S | 31 + 7 files changed, 676 insertions(+), 2 deletions(-) create mode 100644 UefiCpuPkg/Include/Library/BaseRiscVMmuLib.h create mode 100644 UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c create mode 100644 UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf create mode 100644 UefiCpuPkg/Library/BaseRiscVMmuLib/RiscVMmuCore.S diff --git a/UefiCpuPkg/CpuDxeRiscV64/CpuDxe.c b/UefiCpuPkg/CpuDxeRiscV64/C= puDxe.c index 25fe3f54c325..2af3b6223450 100644 --- a/UefiCpuPkg/CpuDxeRiscV64/CpuDxe.c +++ b/UefiCpuPkg/CpuDxeRiscV64/CpuDxe.c @@ -296,8 +296,7 @@ CpuSetMemoryAttributes ( IN UINT64 Attributes ) { - DEBUG ((DEBUG_INFO, "%a: Set memory attributes not supported yet\n", __f= unc__)); - return EFI_SUCCESS; + return RiscVSetMemoryAttributes (BaseAddress, Length, Attributes); } =20 /** @@ -340,6 +339,12 @@ InitializeCpu ( // DisableInterrupts (); =20 + // + // Enable MMU + // + Status =3D RiscVConfigureMmu (); + ASSERT_EFI_ERROR (Status); + // // Install Boot protocol // diff --git a/UefiCpuPkg/CpuDxeRiscV64/CpuDxe.h b/UefiCpuPkg/CpuDxeRiscV64/C= puDxe.h index 49f4e119665a..68e6d038b66e 100644 --- a/UefiCpuPkg/CpuDxeRiscV64/CpuDxe.h +++ b/UefiCpuPkg/CpuDxeRiscV64/CpuDxe.h @@ -15,11 +15,13 @@ #include #include #include +#include #include #include #include #include #include +#include =20 /** Flush CPU data cache. If the instruction cache is fully coherent diff --git a/UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf b/UefiCpuPkg/CpuDxe= RiscV64/CpuDxeRiscV64.inf index e8fa25446aef..9d9a5ef8f247 100644 --- a/UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf +++ b/UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf @@ -37,6 +37,8 @@ TimerLib PeCoffGetEntryPointLib RiscVSbiLib + RiscVMmuLib + CacheMaintenanceLib =20 [Sources] CpuDxe.c diff --git a/UefiCpuPkg/Include/Library/BaseRiscVMmuLib.h b/UefiCpuPkg/Incl= ude/Library/BaseRiscVMmuLib.h new file mode 100644 index 000000000000..f71d6a4a1e7b --- /dev/null +++ b/UefiCpuPkg/Include/Library/BaseRiscVMmuLib.h @@ -0,0 +1,39 @@ +/** @file + + Copyright (c) 2015 - 2016, Linaro Ltd. All rights reserved.
+ Copyright (c) 2023, Ventana Micro Systems Inc. All Rights Reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef BASE_RISCV_MMU_LIB_H_ +#define BASE_RISCV_MMU_LIB_H_ + +VOID +EFIAPI +RiscVLocalTlbFlushAll ( + VOID + ); + +VOID +EFIAPI +RiscVLocalTlbFlush ( + UINTN VirtAddr + ); + +EFI_STATUS +EFIAPI +RiscVSetMemoryAttributes ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes + ); + +EFI_STATUS +EFIAPI +RiscVConfigureMmu ( + VOID + ); + +#endif /* BASE_RISCV_MMU_LIB_H_ */ diff --git a/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c b/UefiCpu= Pkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c new file mode 100644 index 000000000000..230f34261d8b --- /dev/null +++ b/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c @@ -0,0 +1,569 @@ +/** @file +* MMU implementation for RISC-V +* +* Copyright (c) 2011-2020, ARM Limited. All rights reserved. +* Copyright (c) 2016, Linaro Limited. All rights reserved. +* Copyright (c) 2017, Intel Corporation. All rights reserved.
+* Copyright (c) 2023, Ventana Micro Systems Inc. All Rights Reserved.
+* +* SPDX-License-Identifier: BSD-2-Clause-Patent +* +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RISCV_PG_V BIT0 +#define RISCV_PG_R BIT1 +#define RISCV_PG_W BIT2 +#define RISCV_PG_X BIT3 +#define RISCV_PG_G BIT5 +#define RISCV_PG_A BIT6 +#define RISCV_PG_D BIT7 +#define PTE_ATTRIBUTES_MASK 0xE + +#define PTE_PPN_MASK 0x3FFFFFFFFFFC00ULL +#define PTE_PPN_SHIFT 10 +#define RISCV_MMU_PAGE_SHIFT 12 + +STATIC UINTN mMaxRootTableLevel; +STATIC UINTN mBitPerLevel; +STATIC UINTN mTableEntryCount; + +STATIC +BOOLEAN +RiscVMmuEnabled ( + VOID + ) +{ + return ((RiscVGetSupervisorAddressTranslationRegister () & + SATP64_MODE) !=3D (SATP_MODE_OFF << SATP64_MODE_SHIFT)); +} + +STATIC +UINTN +RiscVGetRootTranslateTable ( + VOID + ) +{ + return (RiscVGetSupervisorAddressTranslationRegister () & SATP64_PPN) << + RISCV_MMU_PAGE_SHIFT; +} + +STATIC +BOOLEAN +IsValidPte ( + IN UINTN Entry + ) +{ + if (!(Entry & RISCV_PG_V) || + (((Entry & (RISCV_PG_R | RISCV_PG_W)) =3D=3D RISCV_PG_W))) + { + return FALSE; + } + + return TRUE; +} + +STATIC +UINTN +SetValidPte ( + IN UINTN Entry + ) +{ + /* Set Valid and Global mapping bits */ + return Entry | RISCV_PG_G | RISCV_PG_V; +} + +STATIC +BOOLEAN +IsBlockEntry ( + IN UINTN Entry + ) +{ + return IsValidPte (Entry) && + (Entry & (RISCV_PG_X | RISCV_PG_R)); +} + +STATIC +BOOLEAN +IsTableEntry ( + IN UINTN Entry + ) +{ + return IsValidPte (Entry) && + !IsBlockEntry (Entry); +} + +STATIC +UINTN +SetTableEntry ( + IN UINTN Entry + ) +{ + Entry =3D SetValidPte (Entry); + Entry &=3D ~(RISCV_PG_X | RISCV_PG_W | RISCV_PG_R); + + return Entry; +} + +STATIC +VOID +ReplaceTableEntry ( + IN UINTN *Entry, + IN UINTN Value, + IN UINTN RegionStart, + IN BOOLEAN IsLiveBlockMapping + ) +{ + *Entry =3D Value; + + if (IsLiveBlockMapping && RiscVMmuEnabled ()) { + RiscVLocalTlbFlush (RegionStart); + } +} + +STATIC +UINTN +GetPpnfromPte ( + UINTN Entry, + UINTN Level + ) +{ + return ((Entry & PTE_PPN_MASK) >> PTE_PPN_SHIFT); +} + +STATIC +UINTN +SetPpnToPte ( + UINTN Entry, + UINTN Address, + UINTN Level + ) +{ + UINTN Ppn; + + Ppn =3D ((Address >> RISCV_MMU_PAGE_SHIFT) << PTE_PPN_SHIFT); + ASSERT (~(Ppn & ~PTE_PPN_MASK)); + Entry &=3D ~PTE_PPN_MASK; + return Entry | Ppn; +} + +STATIC +VOID +FreePageTablesRecursive ( + IN UINTN *TranslationTable, + IN UINTN Level + ) +{ + UINTN Index; + + if (Level < mMaxRootTableLevel - 1) { + for (Index =3D 0; Index < mTableEntryCount; Index++) { + if (IsTableEntry (TranslationTable[Index])) { + FreePageTablesRecursive ( + (UINTN *)(GetPpnfromPte ((TranslationTabl= e[Index]), Level) << + RISCV_MMU_PAGE_SHIFT), + Level + 1 + ); + } + } + } + + FreePages (TranslationTable, 1); +} + +STATIC +EFI_STATUS +UpdateRegionMappingRecursive ( + IN UINTN RegionStart, + IN UINTN RegionEnd, + IN UINTN AttributeSetMask, + IN UINTN AttributeClearMask, + IN UINTN *PageTable, + IN UINTN Level, + IN BOOLEAN TableIsLive + ) +{ + EFI_STATUS Status; + UINTN BlockShift; + UINTN BlockMask; + UINTN BlockEnd; + UINTN *Entry; + UINTN EntryValue; + UINTN *TranslationTable; + BOOLEAN NextTableIsLive; + + ASSERT (Level < mMaxRootTableLevel); + ASSERT (((RegionStart | RegionEnd) & EFI_PAGE_MASK) =3D=3D 0); + + BlockShift =3D (mMaxRootTableLevel - Level - 1) * mBitPerLevel + RISCV_M= MU_PAGE_SHIFT; + BlockMask =3D MAX_ADDRESS >> (64 - BlockShift); + + DEBUG ( + ( + DEBUG_VERBOSE, + "%a(%d): %llx - %llx set %lx clr %lx\n", + __func__, + Level, + RegionStart, + RegionEnd, + AttributeSetMask, + AttributeClearMask + ) + ); + + for ( ; RegionStart < RegionEnd; RegionStart =3D BlockEnd) { + BlockEnd =3D MIN (RegionEnd, (RegionStart | BlockMask) + 1); + Entry =3D &PageTable[(RegionStart >> BlockShift) & (mTableEntryCoun= t - 1)]; + + // + // If RegionStart or BlockEnd is not aligned to the block size at this + // level, we will have to create a table mapping in order to map less + // than a block, and recurse to create the block or page entries at + // the next level. No block mappings are allowed at all at level 0, + // so in that case, we have to recurse unconditionally. + // + if ((Level =3D=3D 0) || + (((RegionStart | BlockEnd) & BlockMask) !=3D 0) || IsTableEntry (*= Entry)) + { + ASSERT (Level < mMaxRootTableLevel - 1); + if (!IsTableEntry (*Entry)) { + // + // No table entry exists yet, so we need to allocate a page table + // for the next level. + // + TranslationTable =3D AllocatePages (1); + if (TranslationTable =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + ZeroMem (TranslationTable, EFI_PAGE_SIZE); + + if (IsBlockEntry (*Entry)) { + // + // We are splitting an existing block entry, so we have to popul= ate + // the new table with the attributes of the block entry it repla= ces. + // + Status =3D UpdateRegionMappingRecursive ( + RegionStart & ~BlockMask, + (RegionStart | BlockMask)= + 1, + *Entry & PTE_ATTRIBUTES_M= ASK, + PTE_ATTRIBUTES_MASK, + TranslationTable, + Level + 1, + FALSE + ); + if (EFI_ERROR (Status)) { + // + // The range we passed to UpdateRegionMappingRecursive () is b= lock + // aligned, so it is guaranteed that no further pages were all= ocated + // by it, and so we only have to free the page we allocated he= re. + // + FreePages (TranslationTable, 1); + return Status; + } + } + + NextTableIsLive =3D FALSE; + } else { + TranslationTable =3D (UINTN *)(GetPpnfromPte (*Entry, Level) << RI= SCV_MMU_PAGE_SHIFT); + NextTableIsLive =3D TableIsLive; + } + + // + // Recurse to the next level + // + Status =3D UpdateRegionMappingRecursive ( + RegionStart, + BlockEnd, + AttributeSetMask, + AttributeClearMask, + TranslationTable, + Level + 1, + NextTableIsLive + ); + if (EFI_ERROR (Status)) { + if (!IsTableEntry (*Entry)) { + // + // We are creating a new table entry, so on failure, we can free= all + // allocations we made recursively, given that the whole subhier= archy + // has not been wired into the live page tables yet. (This is not + // possible for existing table entries, since we cannot revert t= he + // modifications we made to the subhierarchy it represents.) + // + FreePageTablesRecursive (TranslationTable, Level + 1); + } + + return Status; + } + + if (!IsTableEntry (*Entry)) { + EntryValue =3D SetPpnToPte (0, (UINTN)TranslationTable, Level); + EntryValue =3D SetTableEntry (EntryValue); + ReplaceTableEntry ( + Entry, + EntryValue, + RegionStart, + TableIsLive + ); + } + } else { + EntryValue =3D (*Entry & ~AttributeClearMask) | AttributeSetMask; + // + // We don't have page fault exception handler when a virtual page is= accessed and + // the A bit is clear, or is written and the D bit is clear. + // So just set A for read and D for write permission. + // + if (AttributeSetMask & RISCV_PG_R) { + EntryValue |=3D RISCV_PG_A; + } + + if (AttributeSetMask & RISCV_PG_W) { + EntryValue |=3D RISCV_PG_D; + } + + EntryValue =3D SetPpnToPte (EntryValue, RegionStart, Level); + EntryValue =3D SetValidPte (EntryValue); + ReplaceTableEntry (Entry, EntryValue, RegionStart, TableIsLive); + } + } + + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +UpdateRegionMapping ( + IN UINTN RegionStart, + IN UINTN RegionLength, + IN UINTN AttributeSetMask, + IN UINTN AttributeClearMask, + IN UINTN *RootTable, + IN BOOLEAN TableIsLive + ) +{ + if (((RegionStart | RegionLength) & EFI_PAGE_MASK) !=3D 0) { + return EFI_INVALID_PARAMETER; + } + + return UpdateRegionMappingRecursive ( + RegionStart, + RegionStart + RegionLength, + AttributeSetMask, + AttributeClearMask, + RootTable, + 0, + TableIsLive + ); +} + +STATIC +UINTN +GcdAttributeToPageAttribute ( + IN UINTN GcdAttributes + ) +{ + UINTN RiscVAttributes =3D RISCV_PG_R | RISCV_PG_W | RISCV_PG_X; + + // Determine protection attributes + if (GcdAttributes & EFI_MEMORY_RO) { + RiscVAttributes &=3D ~(RISCV_PG_W); + } + + // Process eXecute Never attribute + if (GcdAttributes & EFI_MEMORY_XP) { + RiscVAttributes &=3D ~RISCV_PG_X; + } + + return RiscVAttributes; +} + +EFI_STATUS +EFIAPI +RiscVSetMemoryAttributes ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINTN Length, + IN UINTN Attributes + ) +{ + UINTN PageAttributesSet =3D GcdAttributeToPageAttribute (Attributes); + + if (!RiscVMmuEnabled ()) { + return EFI_SUCCESS; + } + + DEBUG ( + ( + DEBUG_VERBOSE, + "%a: Set %llX page attribute 0x%X\n", + __func__, + BaseAddress, + PageAttributesSet + ) + ); + + return UpdateRegionMapping ( + BaseAddress, + Length, + PageAttributesSet, + PTE_ATTRIBUTES_MASK, + (UINTN *)RiscVGetRootTranslateTable (), + TRUE + ); +} + +STATIC +EFI_STATUS +RiscVMmuSetSatpMode ( + UINTN SatpMode + ) +{ + VOID *TranslationTable; + UINTN SatpReg; + UINTN Ppn; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemoryMap; + UINTN NumberOfDescriptors; + UINTN Index; + EFI_STATUS Status; + + switch (SatpMode) { + case SATP_MODE_OFF: + return EFI_SUCCESS; + case SATP_MODE_SV39: + mMaxRootTableLevel =3D 3; + mBitPerLevel =3D 9; + mTableEntryCount =3D 512; + break; + case SATP_MODE_SV48: + mMaxRootTableLevel =3D 4; + mBitPerLevel =3D 9; + mTableEntryCount =3D 512; + break; + case SATP_MODE_SV57: + mMaxRootTableLevel =3D 5; + mBitPerLevel =3D 9; + mTableEntryCount =3D 512; + break; + default: + return EFI_INVALID_PARAMETER; + } + + // Allocate pages for translation table + TranslationTable =3D AllocatePages (1); + if (TranslationTable =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + ZeroMem (TranslationTable, mTableEntryCount * sizeof (UINTN)); + + NumberOfDescriptors =3D 0; + MemoryMap =3D NULL; + Status =3D gDS->GetMemorySpaceMap ( + &NumberOfDescriptors, + &MemoryMap + ); + ASSERT_EFI_ERROR (Status); + + for (Index =3D 0; Index < NumberOfDescriptors; Index++) { + if (MemoryMap[Index].GcdMemoryType =3D=3D EfiGcdMemoryTypeMemoryMapped= Io) { + // Default Read/Write attribute for memory mapped IO + UpdateRegionMapping ( + MemoryMap[Index].BaseAddress, + MemoryMap[Index].Length, + RISCV_PG_R | RISCV_PG_W, + PTE_ATTRIBUTES_MASK, + TranslationTable, + FALSE + ); + } else if (MemoryMap[Index].GcdMemoryType =3D=3D EfiGcdMemoryTypeSyste= mMemory) { + // Default Read/Write/Execute attribute for system memory + UpdateRegionMapping ( + MemoryMap[Index].BaseAddress, + MemoryMap[Index].Length, + RISCV_PG_R | RISCV_PG_W | RISCV_PG_X, + PTE_ATTRIBUTES_MASK, + TranslationTable, + FALSE + ); + } + } + + FreePool ((VOID *)MemoryMap); + + if (GetInterruptState ()) { + DisableInterrupts (); + } + + Ppn =3D (UINTN)TranslationTable >> RISCV_MMU_PAGE_SHIFT; + ASSERT (!(Ppn & ~(SATP64_PPN))); + + SatpReg =3D Ppn; + SatpReg |=3D (SatpMode << + SATP64_MODE_SHIFT) & SATP64_MODE; + RiscVSetSupervisorAddressTranslationRegister (SatpReg); + /* Check if HW support the setup satp mode */ + if (SatpReg !=3D RiscVGetSupervisorAddressTranslationRegister ()) { + DEBUG ( + ( + DEBUG_VERBOSE, + "%a: HW does not support SATP mode:%d\n", + __func__, + SatpMode + ) + ); + FreePageTablesRecursive (TranslationTable, 0); + return EFI_DEVICE_ERROR; + } + + RiscVLocalTlbFlushAll (); + + if (GetInterruptState ()) { + EnableInterrupts (); + } + + return Status; +} + +EFI_STATUS +EFIAPI +RiscVConfigureMmu ( + VOID + ) +{ + EFI_STATUS Status =3D EFI_SUCCESS; + INTN ModeSupport[] =3D { SATP_MODE_SV57, SATP_MODE_SV48, SATP_MOD= E_SV39 }; + INTN Idx; + + /* Try to setup MMU with highest mode as possible */ + for (Idx =3D 0; Idx < ARRAY_SIZE (ModeSupport); Idx++) { + Status =3D RiscVMmuSetSatpMode (ModeSupport[Idx]); + if (Status =3D=3D EFI_DEVICE_ERROR) { + continue; + } else if (EFI_ERROR (Status)) { + return Status; + } + + DEBUG ( + ( + DEBUG_INFO, + "%a: SATP mode %d successfully configured\n", + __func__, + ModeSupport[Idx] + ) + ); + break; + } + + return Status; +} diff --git a/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf b/UefiC= puPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf new file mode 100644 index 000000000000..b8a95feee683 --- /dev/null +++ b/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf @@ -0,0 +1,26 @@ +## @file +# +# Copyright (c) 2023, Ventana Micro Systems Inc. All Rights Reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001b + BASE_NAME =3D BaseRiscVMmuLib + FILE_GUID =3D d3bc42ee-c9eb-4339-ba11-06747083d3ae + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RiscVMmuLib + +[Sources] + BaseRiscVMmuLib.c + RiscVMmuCore.S + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib diff --git a/UefiCpuPkg/Library/BaseRiscVMmuLib/RiscVMmuCore.S b/UefiCpuPkg= /Library/BaseRiscVMmuLib/RiscVMmuCore.S new file mode 100644 index 000000000000..42eec4cbdf83 --- /dev/null +++ b/UefiCpuPkg/Library/BaseRiscVMmuLib/RiscVMmuCore.S @@ -0,0 +1,31 @@ +/** @file +* +* Copyright (c) 2023, Ventana Micro Systems Inc. All Rights Reserved.
+* +* SPDX-License-Identifier: BSD-2-Clause-Patent +* +**/ + +#include +#include + +.text + .align 3 + +// +// Local tlb flush all. +// +// +ASM_FUNC (RiscVLocalTlbFlushAll) +sfence.vma +ret + +// +// Local tlb flush at a virtual address +// @retval a0 : virtual address. +// +ASM_FUNC ( + RiscVLocalTlbFlush + ) +sfence.vma a0 +ret --=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 (#105342): https://edk2.groups.io/g/devel/message/105342 Mute This Topic: https://groups.io/mt/99159996/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 Sun May 19 00:47:56 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+105343+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+105343+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1685143066; cv=none; d=zohomail.com; s=zohoarc; b=Sc9G55rybwQHihWR+FzthBDU+YJNlQwM9LPv4SgZ7i/tsNlFgCWQCHH814tmecEqDNPD0+VkJ+mYZE7AGbhZCB+Bajwj0GChbxZ0VIwdI5psY2V0aVCNlAfXlS6OSlXrtQgctoLGUZPSwAjnxHCAyHNAittnxOLUTX0DNcV+XxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685143066; 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=NgKbGs6XDx8rogoEGhEZwFRyU67U1yh0bqGyMxVEqCI=; b=K95ados0qqkbXkYL/mtCcFpO86Bqf2apsm1PvPcgFBtsyoQLqA+DxnjhF/2onPCOglicqFDbTeQk/TSLnKcUej2PD4TtC4mn84Ime1rYezj3mzxZXFBcLTrsnZEkWkt8IxaU3b2JLP6fe6TLxhbcTO+0Z2kzYQ4sKWtb9PiSfXI= 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+105343+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685143066618815.0061941763191; Fri, 26 May 2023 16:17:46 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4BvLYY1788612x74vEHgqKbU; Fri, 26 May 2023 16:17:46 -0700 X-Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by mx.groups.io with SMTP id smtpd.web10.1086.1685143065768261588 for ; Fri, 26 May 2023 16:17:45 -0700 X-Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-64d4e4598f0so1714804b3a.2 for ; Fri, 26 May 2023 16:17:45 -0700 (PDT) X-Gm-Message-State: Cjfv9cPUdP5zGVoMjrhOf0Jjx1787277AA= X-Google-Smtp-Source: ACHHUZ6gFBNV/2iDUl4bDvOa+9nvy3F/HvU6h7yCCf+9i0dCTVKhsyerhlDs+Do5A30rCyZF5y62Ig== X-Received: by 2002:a05:6a00:891:b0:636:e52f:631e with SMTP id q17-20020a056a00089100b00636e52f631emr5389725pfj.1.1685143064852; Fri, 26 May 2023 16:17:44 -0700 (PDT) X-Received: from localhost.localdomain (c-174-50-177-95.hsd1.ca.comcast.net. [174.50.177.95]) by smtp.gmail.com with ESMTPSA id k3-20020aa792c3000000b005d22639b577sm3106308pfa.165.2023.05.26.16.17.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 16:17:44 -0700 (PDT) From: "Tuan Phan" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, gaoliming@byosoft.com.cn, zhiguang.liu@intel.com, sunilvl@ventanamicro.com, git@danielschaefer.me, andrei.warkentin@intel.com, Tuan Phan Subject: [edk2-devel] [PATCH v3 4/7] OvmfPkg/RiscVVirt: Remove satp bare mode setting Date: Fri, 26 May 2023 16:17:30 -0700 Message-Id: <20230526231733.6755-5-tphan@ventanamicro.com> In-Reply-To: <20230526231733.6755-1-tphan@ventanamicro.com> References: <20230526231733.6755-1-tphan@ventanamicro.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,tphan@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685143066; bh=Yrt4OeU2LWgUQlFtKB+zru/BFiE87lQNM1u7OcRG7Js=; h=Cc:Date:From:Reply-To:Subject:To; b=AYxgkKbYtGcdZ6pvcyx2I1uKXlNTYIgMwhHjpJ1UcQFYr0p/E1+ZlRN+PghDBNxZ5/w oR+Wd2kJSKE+rk+8NprvaTZAyjmyUnh4Ljoa/lPBB74TTvsEhR4GVGDiyEQ6/9loxky5X IGh1TXLQGlkROJJ/1oIf5zY2SPM4jBL2obI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685143067224100015 Content-Type: text/plain; charset="utf-8" MMU now is initialized in CpuDxe. There is no point to set satp to bare mode as that should be the default mode when booting edk2. Signed-off-by: Tuan Phan Reviewed-by: Andrei Warkentin Reviewed-by: Sunil V L --- OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc | 1 + OvmfPkg/RiscVVirt/Sec/Memory.c | 18 ++---------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc b/OvmfPkg/RiscVVirt/RiscVV= irt.dsc.inc index 731f54f73f81..bc204ba5fe52 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc +++ b/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc @@ -83,6 +83,7 @@ # RISC-V Architectural Libraries CpuExceptionHandlerLib|UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandler= Lib/BaseRiscV64CpuExceptionHandlerLib.inf RiscVSbiLib|MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf + RiscVMmuLib|UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf PlatformBootManagerLib|OvmfPkg/RiscVVirt/Library/PlatformBootManagerLib/= PlatformBootManagerLib.inf ResetSystemLib|OvmfPkg/RiscVVirt/Library/ResetSystemLib/BaseResetSystemL= ib.inf =20 diff --git a/OvmfPkg/RiscVVirt/Sec/Memory.c b/OvmfPkg/RiscVVirt/Sec/Memory.c index 0e2690c73687..aad71ee5dcbb 100644 --- a/OvmfPkg/RiscVVirt/Sec/Memory.c +++ b/OvmfPkg/RiscVVirt/Sec/Memory.c @@ -85,21 +85,6 @@ AddMemoryRangeHob ( AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase)); } =20 -/** - Configure MMU -**/ -STATIC -VOID -InitMmu ( - ) -{ - // - // Set supervisor translation mode to Bare mode - // - RiscVSetSupervisorAddressTranslationRegister ((UINT64)SATP_MODE_OFF << 6= 0); - DEBUG ((DEBUG_INFO, "%a: Set Supervisor address mode to bare-metal mode.= \n", __func__)); -} - /** Publish system RAM and reserve memory regions. =20 @@ -327,7 +312,8 @@ MemoryPeimInitialization ( =20 AddReservedMemoryMap (FdtPointer); =20 - InitMmu (); + /* Make sure SEC is booting with bare mode */ + ASSERT ((RiscVGetSupervisorAddressTranslationRegister () & SATP64_MODE) = =3D=3D (SATP_MODE_OFF << SATP64_MODE_SHIFT)); =20 BuildMemoryTypeInformationHob (); =20 --=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 (#105343): https://edk2.groups.io/g/devel/message/105343 Mute This Topic: https://groups.io/mt/99159997/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 Sun May 19 00:47:56 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+105344+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+105344+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1685143067; cv=none; d=zohomail.com; s=zohoarc; b=VPKBDq0trd1ZqkjdQU9jD2FPMJTADq3ZIqpMqzhax0LXaVoyMe7EvfJZTBBKHHbmWGKzVNn0AVqhExz7oOs+J0nXsXuH/F9+/8Rs/Cly1tiDBV44xsB2MwwjcUEFNNqTNeTbXn+jTT1rfGhwL+bnPQeKKCxrnNLntNuuC9DDvmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685143067; 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=1Qz2AA+mwxUNTtvrhbL+A934qC4jd7euqnR3LWQXo7Y=; b=ICcE6Lij+uUtGNwbF6xs4iDZegIHHdEHyuGxPKGbFMYaq9Cl6Usl6xkmX6FhCQfn/v+PIF43/cW5r9zCYszNyBoOUyeP12A/2xXk4EiuDkHJWbJ1UHQFp1stx7oObdQy9SY3DLCxS8c1XYZ6c+qpvvbLM7s8LQYDAONoHKghkZI= 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+105344+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685143067707256.7145349107325; Fri, 26 May 2023 16:17:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7zeNYY1788612xJMob0pToyy; Fri, 26 May 2023 16:17:47 -0700 X-Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by mx.groups.io with SMTP id smtpd.web11.1176.1685143066974375645 for ; Fri, 26 May 2023 16:17:47 -0700 X-Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-64d3fbb8c1cso1709963b3a.3 for ; Fri, 26 May 2023 16:17:46 -0700 (PDT) X-Gm-Message-State: woZhOVxOIa7v61xCCCTmOWuox1787277AA= X-Google-Smtp-Source: ACHHUZ7081Izcwkqj1PKKYp2Cf1o5ktWll0fVXdgh5iJV4ARtg1MP1uw3gXgcLkY+dknzPmyWbxSKg== X-Received: by 2002:a05:6a00:1356:b0:648:1311:fbc4 with SMTP id k22-20020a056a00135600b006481311fbc4mr5640335pfu.33.1685143066123; Fri, 26 May 2023 16:17:46 -0700 (PDT) X-Received: from localhost.localdomain (c-174-50-177-95.hsd1.ca.comcast.net. [174.50.177.95]) by smtp.gmail.com with ESMTPSA id k3-20020aa792c3000000b005d22639b577sm3106308pfa.165.2023.05.26.16.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 16:17:45 -0700 (PDT) From: "Tuan Phan" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, gaoliming@byosoft.com.cn, zhiguang.liu@intel.com, sunilvl@ventanamicro.com, git@danielschaefer.me, andrei.warkentin@intel.com, Tuan Phan Subject: [edk2-devel] [PATCH v3 5/7] OvmfPkg/RiscVVirt: VirtNorFlashPlatformLib: Fix wrong flash size Date: Fri, 26 May 2023 16:17:31 -0700 Message-Id: <20230526231733.6755-6-tphan@ventanamicro.com> In-Reply-To: <20230526231733.6755-1-tphan@ventanamicro.com> References: <20230526231733.6755-1-tphan@ventanamicro.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,tphan@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685143067; bh=sodAI2CvUeXnWqo7okqkFGeFzEaCX/mzV9gSY1eziLM=; h=Cc:Date:From:Reply-To:Subject:To; b=eHiXEkVhzGGN8sgL8MqUwf61iAtiIZXzsBrNUjnIN8sn89ENCvKAr8pzR8ypGqbqTwv US1t69Ri2H6GAoJxWaRjjMFidB+fbFi5e2LZWFOBNu1l3dHIPTIJwKTPBDXz1dcYGm63q NGwDt3wOMFd17XI0UHZMkxSvsj4GHs4UmBg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685143069231100022 Content-Type: text/plain; charset="utf-8" The size should be for single region, not the whole firmware FD. Signed-off-by: Tuan Phan Reviewed-by: Andrei Warkentin Reviewed-by: Sunil V L --- .../Library/VirtNorFlashPlatformLib/VirtNorFlashStaticLib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/RiscVVirt/Library/VirtNorFlashPlatformLib/VirtNorFlash= StaticLib.c b/OvmfPkg/RiscVVirt/Library/VirtNorFlashPlatformLib/VirtNorFlas= hStaticLib.c index fdc2ccb6294e..33f3a01b06f4 100644 --- a/OvmfPkg/RiscVVirt/Library/VirtNorFlashPlatformLib/VirtNorFlashStaticL= ib.c +++ b/OvmfPkg/RiscVVirt/Library/VirtNorFlashPlatformLib/VirtNorFlashStaticL= ib.c @@ -24,7 +24,8 @@ VIRT_NOR_FLASH_DESCRIPTION mNorFlashDevice =3D { FixedPcdGet32 (PcdOvmfFdBaseAddress), FixedPcdGet64 (PcdFlashNvStorageVariableBase), - FixedPcdGet32 (PcdOvmfFirmwareFdSize), + FixedPcdGet32 (PcdOvmfFirmwareFdSize) - + (FixedPcdGet64 (PcdFlashNvStorageVariableBase) - FixedPcdGet32 (PcdOvmfF= dBaseAddress)), QEMU_NOR_BLOCK_SIZE }; =20 --=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 (#105344): https://edk2.groups.io/g/devel/message/105344 Mute This Topic: https://groups.io/mt/99159998/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 Sun May 19 00:47:56 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+105345+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+105345+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1685143069; cv=none; d=zohomail.com; s=zohoarc; b=J0+G9KjkJZM05lp4M7CCt7nP9p7Yt1UZB4QbF1ZhalarPFZdrX0w852u+K9OSWN3UxQphm1zlO0HuFwdadvXFo65a3BWBZBhfA6aUhcmF1SR60HG4a7mBDdiQmECg/JiwDHI+eRj71VLnoyE6bUfBq53UP+sw5lTHS5M+zZ3OIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685143069; 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=Fv6dEQ8B/6Bv/fkfwhBXcOve/e52sIMkwlMDEOUN1Xw=; b=oI4fKnNmzPgOx09ZIiNldsVDDq2jqRMURk55y0a0FZD9m4jtaR0TPQqii4KS3p7nmhMJg5Au9DcKPar+egJGJTy7+zvicMZnfq63+YPntv4bK0AR+ZlzVZCGuOWxL4zfwXMPmY5P8eRDHbkw6cpqKAcmUgqgwCeFq8ko6CjQi1E= 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+105345+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 168514306976022.37064998060623; Fri, 26 May 2023 16:17:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qTwyYY1788612xOwwnYXvtUc; Fri, 26 May 2023 16:17:49 -0700 X-Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mx.groups.io with SMTP id smtpd.web10.1087.1685143068705126225 for ; Fri, 26 May 2023 16:17:48 -0700 X-Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-64d604cc0aaso1238696b3a.2 for ; Fri, 26 May 2023 16:17:48 -0700 (PDT) X-Gm-Message-State: ww0A4xKjQOLHzG3rVOv0KdxYx1787277AA= X-Google-Smtp-Source: ACHHUZ75Za2GdfmwKFg31sIQ5oJqV0JX/Qg4Ms/F2pcbHaGPjICQzfcdaBN9bZxEQMbmjDc1Rnu4cQ== X-Received: by 2002:a05:6a20:8408:b0:10b:97c8:2e16 with SMTP id c8-20020a056a20840800b0010b97c82e16mr1432705pzd.29.1685143067407; Fri, 26 May 2023 16:17:47 -0700 (PDT) X-Received: from localhost.localdomain (c-174-50-177-95.hsd1.ca.comcast.net. [174.50.177.95]) by smtp.gmail.com with ESMTPSA id k3-20020aa792c3000000b005d22639b577sm3106308pfa.165.2023.05.26.16.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 16:17:47 -0700 (PDT) From: "Tuan Phan" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, gaoliming@byosoft.com.cn, zhiguang.liu@intel.com, sunilvl@ventanamicro.com, git@danielschaefer.me, andrei.warkentin@intel.com, Tuan Phan Subject: [edk2-devel] [PATCH v3 6/7] OvmfPkg/VirtNorFlashDxe: Not add memory space if it exists Date: Fri, 26 May 2023 16:17:32 -0700 Message-Id: <20230526231733.6755-7-tphan@ventanamicro.com> In-Reply-To: <20230526231733.6755-1-tphan@ventanamicro.com> References: <20230526231733.6755-1-tphan@ventanamicro.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,tphan@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685143069; bh=upnIFt1FJwsoWpfihr5mG/PpGoM4kfZmy1E82vqVHZs=; h=Cc:Date:From:Reply-To:Subject:To; b=QAjNgBYIYLZ/+Gb1qeWq2RjG2TqljXE7bGcUcYDDaZvUzVUNcoHlP1FaxAr/TVSSlLE cSZFpS/Ty6NxLADCNIKcSF86ZMbdXsu+uWwbtDsyFKZSYVdond+8E83WNPma9Hr8Ch7eV SJnWEawnwPXZt7ZI8lAz9JRK/43celGEDJM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685143071253100028 Content-Type: text/plain; charset="utf-8" The flash base address can be added to GCD before this driver run. So only add it if it has not been done. Signed-off-by: Tuan Phan Reviewed-by: Andrei Warkentin --- OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c | 25 +++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c b/OvmfPkg/VirtNorFla= shDxe/VirtNorFlashDxe.c index 6b9ef261335e..bbd1697a51dd 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c @@ -372,10 +372,11 @@ NorFlashFvbInitialize ( IN NOR_FLASH_INSTANCE *Instance ) { - EFI_STATUS Status; - UINT32 FvbNumLba; - EFI_BOOT_MODE BootMode; - UINTN RuntimeMmioRegionSize; + EFI_STATUS Status; + UINT32 FvbNumLba; + EFI_BOOT_MODE BootMode; + UINTN RuntimeMmioRegionSize; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc; =20 DEBUG ((DEBUG_BLKIO, "NorFlashFvbInitialize\n")); ASSERT ((Instance !=3D NULL)); @@ -390,13 +391,19 @@ NorFlashFvbInitialize ( // is written as the base of the flash region (ie: Instance->Devic= eBaseAddress) RuntimeMmioRegionSize =3D (Instance->RegionBaseAddress - Instance->Devic= eBaseAddress) + Instance->Size; =20 - Status =3D gDS->AddMemorySpace ( - EfiGcdMemoryTypeMemoryMappedIo, + Status =3D gDS->GetMemorySpaceDescriptor ( Instance->DeviceBaseAddress, - RuntimeMmioRegionSize, - EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + &Desc ); - ASSERT_EFI_ERROR (Status); + if (Status =3D=3D EFI_NOT_FOUND) { + Status =3D gDS->AddMemorySpace ( + EfiGcdMemoryTypeMemoryMappedIo, + Instance->DeviceBaseAddress, + RuntimeMmioRegionSize, + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + ); + ASSERT_EFI_ERROR (Status); + } =20 Status =3D gDS->SetMemorySpaceAttributes ( Instance->DeviceBaseAddress, --=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 (#105345): https://edk2.groups.io/g/devel/message/105345 Mute This Topic: https://groups.io/mt/99159999/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 Sun May 19 00:47:56 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+105346+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+105346+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1685143070; cv=none; d=zohomail.com; s=zohoarc; b=S1PsXhSb3c/s96Oi16Y9odqKLfWNyHpKqYZDBBFKikuji/7VflCKXvK/Z39yrCEZV9XGpw99XacQR4WLG5baXSbUQU3AGGHg5wPnah4XmepyjkLgqDl3MeW925b7YO0qakzCB+JM4NhL3B9sC4b9w+QHEULElGkzbcOHg77zelg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685143070; 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=ZppRXJRVh3FWbvnmEhPCh4YkrtkPmax0lxDbRYFPHgE=; b=KbC8iJ+ta4AIqKNLToe/IvJaGOhSfLgmbGVpOWHNK/dC5f6RFYpnYcrvuOslkNHOb8jLoYPmKqjV+oRMvA9lJ/QC8xunZ9aPD6XfaTQjGA+yBm50ktk6pbO7TXyTbLaQ+yxx3ldy9cpP0A/HWg9opfUouDZcgZuLW+PJmMTogqQ= 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+105346+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 168514307055042.9658669643394; Fri, 26 May 2023 16:17:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZmqdYY1788612xu56FIcjh7g; Fri, 26 May 2023 16:17:50 -0700 X-Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mx.groups.io with SMTP id smtpd.web11.1177.1685143069593364878 for ; Fri, 26 May 2023 16:17:49 -0700 X-Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-64d44b198baso1048260b3a.0 for ; Fri, 26 May 2023 16:17:49 -0700 (PDT) X-Gm-Message-State: 59UCQaFLPkuP5dhgFt4QCM0Ix1787277AA= X-Google-Smtp-Source: ACHHUZ7/gWRvXe1FNRQTi0TbNjX9w1cdv7hLeZX/SR35nVwK+epw/PNtbJGJplxIeQ+SDdJcKwBzvg== X-Received: by 2002:a05:6a00:23ca:b0:63d:6744:8cae with SMTP id g10-20020a056a0023ca00b0063d67448caemr796336pfc.2.1685143068684; Fri, 26 May 2023 16:17:48 -0700 (PDT) X-Received: from localhost.localdomain (c-174-50-177-95.hsd1.ca.comcast.net. [174.50.177.95]) by smtp.gmail.com with ESMTPSA id k3-20020aa792c3000000b005d22639b577sm3106308pfa.165.2023.05.26.16.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 16:17:48 -0700 (PDT) From: "Tuan Phan" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, gaoliming@byosoft.com.cn, zhiguang.liu@intel.com, sunilvl@ventanamicro.com, git@danielschaefer.me, andrei.warkentin@intel.com, Tuan Phan Subject: [edk2-devel] [PATCH v3 7/7] OvmfPkg/RiscVVirt: SEC: Add IO memory resource hob for platform devices Date: Fri, 26 May 2023 16:17:33 -0700 Message-Id: <20230526231733.6755-8-tphan@ventanamicro.com> In-Reply-To: <20230526231733.6755-1-tphan@ventanamicro.com> References: <20230526231733.6755-1-tphan@ventanamicro.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,tphan@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685143070; bh=DX/1fWY1MqWSjvPIJCc8qYDfjgNoSSQCesuQUtgz/Vs=; h=Cc:Date:From:Reply-To:Subject:To; b=XE6JwksSLpJnQSWimexZ5eLQXnl0s0Gsk3kcK97mBEGHf6a/nG8uGdC4tEtoJ/NScGN 4XE86Iubxd6vF2CSh0rdQpchommopjoy/mDzCbmiZBKTerrELxOOuFyLBMygDqH/C5zXo DEh7WggnQD2EesVlPCnla/PjhnWnrV2RISQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685143071250100027 Content-Type: text/plain; charset="utf-8" Normally, DXE driver would add device resource to GCD before start using. But some key resources such as uart, flash base address are being accessing directly in some core modules. Those resources should be populated to HOB in SEC phase so they are added to GCD before anyone can access them. Signed-off-by: Tuan Phan Reviewed-by: Andrei Warkentin --- OvmfPkg/RiscVVirt/Sec/Platform.c | 62 +++++++++++++++++++++++++++++++ OvmfPkg/RiscVVirt/Sec/SecMain.inf | 1 + 2 files changed, 63 insertions(+) diff --git a/OvmfPkg/RiscVVirt/Sec/Platform.c b/OvmfPkg/RiscVVirt/Sec/Platf= orm.c index 3645c27b0b12..944b82c84a6e 100644 --- a/OvmfPkg/RiscVVirt/Sec/Platform.c +++ b/OvmfPkg/RiscVVirt/Sec/Platform.c @@ -21,6 +21,63 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include =20 +/** + Build memory map I/O range resource HOB using the + base address and size. + + @param MemoryBase Memory map I/O base. + @param MemorySize Memory map I/O size. + +**/ +STATIC +VOID +AddIoMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ) +{ + /* Align to EFI_PAGE_SIZE */ + MemorySize =3D ALIGN_VALUE (MemorySize, EFI_PAGE_SIZE); + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_MAPPED_IO, + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_TESTED, + MemoryBase, + MemorySize + ); +} + +/** + Populate IO resources from FDT that not added to GCD by its + driver in the DXE phase.=20 + + @param FdtBase Fdt base address + @param Compatible Compatible string + +**/ +STATIC +VOID +PopulateIoResources ( + VOID *FdtBase, + CONST CHAR8* Compatible + ) +{ + UINT64 *Reg; + INT32 Node, LenP; + + Node =3D fdt_node_offset_by_compatible (FdtBase, -1, Compatible); + while (Node !=3D -FDT_ERR_NOTFOUND) { + Reg =3D (UINT64 *)fdt_getprop (FdtBase, Node, "reg", &LenP); + if (Reg) { + ASSERT (LenP =3D=3D (2 * sizeof (UINT64))); + AddIoMemoryBaseSizeHob (SwapBytes64 (Reg[0]), SwapBytes64 (Reg[1])); + } + Node =3D fdt_node_offset_by_compatible (FdtBase, Node, Compatible); + } +} + /** @retval EFI_SUCCESS The address of FDT is passed in HOB. EFI_UNSUPPORTED Can't locate FDT. @@ -80,5 +137,10 @@ PlatformPeimInitialization ( =20 BuildFvHob (PcdGet32 (PcdOvmfDxeMemFvBase), PcdGet32 (PcdOvmfDxeMemFvSiz= e)); =20 + PopulateIoResources (Base, "ns16550a"); + PopulateIoResources (Base, "qemu,fw-cfg-mmio"); + PopulateIoResources (Base, "virtio,mmio"); + AddIoMemoryBaseSizeHob (PcdGet32 (PcdOvmfFdBaseAddress), PcdGet32 (PcdOv= mfFirmwareFdSize)); + return EFI_SUCCESS; } diff --git a/OvmfPkg/RiscVVirt/Sec/SecMain.inf b/OvmfPkg/RiscVVirt/Sec/SecM= ain.inf index 0e2a5785e8a4..75d5b74b3d3f 100644 --- a/OvmfPkg/RiscVVirt/Sec/SecMain.inf +++ b/OvmfPkg/RiscVVirt/Sec/SecMain.inf @@ -62,6 +62,7 @@ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize =20 [Guids] gFdtHobGuid --=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 (#105346): https://edk2.groups.io/g/devel/message/105346 Mute This Topic: https://groups.io/mt/99160000/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-