From patchwork Tue Jul 23 07:57:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Zong-You Xie X-Patchwork-Id: 1963640 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ZuXcfz4a; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WSqJL4jGNz1yXp for ; Tue, 23 Jul 2024 17:57:54 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vrT1DMIDW9K1KATtnlrH4oW1UZ1hq4Z9LsPg/0MFlgE=; b=ZuXcfz4aH5Q2Np JzZCS0UFQIVFNzPC0JizJ14oqP8sNLFWGZRTMaE0lAL6Z1TpFjtdOIkyUPZcoqtku3JV02TUHvvxe TH7VRRYJbkWb5PsXReXS7TndQ//EqxMW22ma5TUj6xmHJtjd1+W5O+IaBbOuE0gPiXOABfr6GgOxX 2fqaAyBZ9YFUeyVnzYonxVDo4XT6FswNWXt/+9SO9eHfXyYRJn+x+dPmUsgau+AF3+0pFiynpWp6o 0asdU890hd1C2m2vd18qoiuSlVJZP4fYjZRyc3vPxCkHIh9DgDdMY7v2yjRzieucsSHd2V19eiDXi 8wm+2dQLP0GuufGw/1gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWAP3-0000000BmUW-112C; Tue, 23 Jul 2024 07:57:45 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWAOz-0000000BmSm-3JTL for opensbi@lists.infradead.org; Tue, 23 Jul 2024 07:57:44 +0000 Received: from mail.andestech.com (ATCPCS31.andestech.com [10.0.1.89]) by Atcsqr.andestech.com with ESMTPS id 46N7vXjO035907 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 23 Jul 2024 15:57:33 +0800 (+08) (envelope-from ben717@andestech.com) Received: from atctrx.andestech.com (10.0.15.190) by ATCPCS31.andestech.com (10.0.1.89) with Microsoft SMTP Server id 14.3.498.0; Tue, 23 Jul 2024 15:57:33 +0800 From: Ben Zong-You Xie To: CC: Ben Zong-You Xie Subject: [PATCH 1/4] platform: generic: Kconfig: add the description for Andes PMA feature Date: Tue, 23 Jul 2024 15:57:25 +0800 Message-ID: <20240723075728.587110-2-ben717@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240723075728.587110-1-ben717@andestech.com> References: <20240723075728.587110-1-ben717@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.190] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 46N7vXjO035907 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240723_005742_118935_15D64C03 X-CRM114-Status: UNSURE ( 9.02 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Describe Andes PPMA in the config option, and select it for AE350 platform. Signed-off-by: Ben Zong-You Xie --- platform/generic/Kconfig | 1 + platform/generic/andes/Kconfig | 5 +++++ 2 files changed, 6 insertions(+) Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 TVD_RCVD_IP Message was received from an IP address 1.0 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Describe Andes PPMA in the config option, and select it for AE350 platform. Signed-off-by: Ben Zong-You Xie Reviewed-by: Anup Patel --- platform/generic/Kconfig | 1 + platform/generic/andes/Kconfig | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/platform/generic/Kconfig b/platform/generic/Kconfig index 6642a6e..688da3f 100644 --- a/platform/generic/Kconfig +++ b/platform/generic/Kconfig @@ -33,6 +33,7 @@ config PLATFORM_ANDES_AE350 bool "Andes AE350 support" select SYS_ATCSMU select ANDES_PMU + select ANDES_PMA default n config PLATFORM_RENESAS_RZFIVE diff --git a/platform/generic/andes/Kconfig b/platform/generic/andes/Kconfig index 138710b..6edd67d 100644 --- a/platform/generic/andes/Kconfig +++ b/platform/generic/andes/Kconfig @@ -3,6 +3,11 @@ config ANDES_PMA bool "Andes PMA support" default n + help + Programmable PMA(PPMA) is a feature for Andes. PPMA allows + dynamic adjustment of memory attributes in the runtime. + It contains a configurable amount of PMA entries implemented + as CSRs to control the attributes of memory locations in interest. config ANDES_SBI bool "Andes SBI support" From patchwork Tue Jul 23 07:57:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Zong-You Xie X-Patchwork-Id: 1963642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=X16AquA5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WSqJM41Whz1yXp for ; Tue, 23 Jul 2024 17:57:55 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1FVPGDxGcOsBS9Po6MwkjgwYPTg/BmoBjgpxeBsql1Q=; b=X16AquA5CD/yta FPIgBPbPDsn4hoyR6JtuQEbnC8d3Q/0i3U13k2ccEVgMMWbsiq2jzFngHd+5XluSSIRiUqdK91cvz syHsVhbrUJr2qCrZzves/GrXFsIqi6Z1VJ97/Q1VZtIbd4fFarovTdB9Zx9KfKaRcUO6W/IB61ILu CcGWOjGrwtRFGSyEYc4yn4hY6fIb7CgQxcFWz/3GRa6PKtHzecM384NoEsBB5SwiLw59fAqbBrUkK 2imdMtvsT+HmTOuJ/LAs/vDtTZC05Ki83HuqPsiWIqNk8TWLTfxdxalkCJiJCFqpRvnCBH6uHwwbs P7Yxi0vSHhNKwu4GuYLA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWAP6-0000000BmXP-3GFT; Tue, 23 Jul 2024 07:57:48 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWAP3-0000000BmUK-2MRq for opensbi@lists.infradead.org; Tue, 23 Jul 2024 07:57:48 +0000 Received: from mail.andestech.com (ATCPCS31.andestech.com [10.0.1.89]) by Atcsqr.andestech.com with ESMTPS id 46N7vYoG035908 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 23 Jul 2024 15:57:34 +0800 (+08) (envelope-from ben717@andestech.com) Received: from atctrx.andestech.com (10.0.15.190) by ATCPCS31.andestech.com (10.0.1.89) with Microsoft SMTP Server id 14.3.498.0; Tue, 23 Jul 2024 15:57:34 +0800 From: Ben Zong-You Xie To: CC: Ben Zong-You Xie Subject: [PATCH 2/4] platform: generic: andes: add a new Andes SBI call to probe Andes PMA feature Date: Tue, 23 Jul 2024 15:57:26 +0800 Message-ID: <20240723075728.587110-3-ben717@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240723075728.587110-1-ben717@andestech.com> References: <20240723075728.587110-1-ben717@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.190] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 46N7vYoG035908 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240723_005745_898915_2245F455 X-CRM114-Status: GOOD ( 18.18 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add a new Andes SBI call to check whether PPMA is supported by hardware or not. Signed-off-by: Ben Zong-You Xie --- platform/generic/andes/ae350.c | 2 ++ platform/generic/andes/andes_pma.c | 8 ++++++-- platform/generic/andes/andes_sbi.c | 5 +++++ platform/g [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 TVD_RCVD_IP Message was received from an IP address 1.0 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add a new Andes SBI call to check whether PPMA is supported by hardware or not. Signed-off-by: Ben Zong-You Xie Reviewed-by: Anup Patel --- platform/generic/andes/ae350.c | 2 ++ platform/generic/andes/andes_pma.c | 8 ++++++-- platform/generic/andes/andes_sbi.c | 5 +++++ platform/generic/include/andes/andes_pma.h | 12 ++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/platform/generic/andes/ae350.c b/platform/generic/andes/ae350.c index 63c10bc..a1ab6b9 100644 --- a/platform/generic/andes/ae350.c +++ b/platform/generic/andes/ae350.c @@ -19,6 +19,7 @@ #include #include #include +#include static struct smu_data smu = { 0 }; extern void __ae350_enable_coherency_warmboot(void); @@ -120,4 +121,5 @@ const struct platform_override andes_ae350 = { .final_init = ae350_final_init, .extensions_init = andes_pmu_extensions_init, .pmu_init = andes_pmu_init, + .vendor_ext_provider = andes_sbi_vendor_ext_provider, }; diff --git a/platform/generic/andes/andes_pma.c b/platform/generic/andes/andes_pma.c index 9c37720..a884bf7 100644 --- a/platform/generic/andes/andes_pma.c +++ b/platform/generic/andes/andes_pma.c @@ -241,7 +241,6 @@ static int andes_fdt_reserved_memory_fixup(void *fdt, int andes_pma_setup_regions(const struct andes_pma_region *pma_regions, unsigned int pma_regions_count) { - unsigned long mmsc = csr_read(CSR_MMSC_CFG); unsigned int dt_populate_cnt; unsigned int i, j; unsigned long pa; @@ -254,7 +253,7 @@ int andes_pma_setup_regions(const struct andes_pma_region *pma_regions, if (pma_regions_count > ANDES_MAX_PMA_REGIONS) return SBI_EINVAL; - if ((mmsc & MMSC_CFG_PPMA_MASK) == 0) + if (!andes_sbi_probe_pma()) return SBI_ENOTSUPP; /* Configure the PMA regions */ @@ -290,3 +289,8 @@ int andes_pma_setup_regions(const struct andes_pma_region *pma_regions, return 0; } + +bool andes_sbi_probe_pma(void) +{ + return (csr_read(CSR_MMSC_CFG) & MMSC_CFG_PPMA_MASK) ? true : false; +} diff --git a/platform/generic/andes/andes_sbi.c b/platform/generic/andes/andes_sbi.c index 43bafdc..a7ca4a5 100644 --- a/platform/generic/andes/andes_sbi.c +++ b/platform/generic/andes/andes_sbi.c @@ -5,12 +5,14 @@ */ #include #include +#include #include #include enum sbi_ext_andes_fid { SBI_EXT_ANDES_FID0 = 0, /* Reserved for future use */ SBI_EXT_ANDES_IOCP_SW_WORKAROUND, + SBI_EXT_ANDES_PMA_PROBE, }; static bool andes_cache_controllable(void) @@ -41,6 +43,9 @@ int andes_sbi_vendor_ext_provider(long funcid, case SBI_EXT_ANDES_IOCP_SW_WORKAROUND: out->value = andes_apply_iocp_sw_workaround(); break; + case SBI_EXT_ANDES_PMA_PROBE: + out->value = andes_sbi_probe_pma(); + break; default: return SBI_EINVAL; diff --git a/platform/generic/include/andes/andes_pma.h b/platform/generic/include/andes/andes_pma.h index 5ea1247..147dca1 100644 --- a/platform/generic/include/andes/andes_pma.h +++ b/platform/generic/include/andes/andes_pma.h @@ -47,4 +47,16 @@ struct andes_pma_region { int andes_pma_setup_regions(const struct andes_pma_region *pma_regions, unsigned int pma_regions_count); +/** + * Programmable PMA(PPMA) is a feature for Andes. PPMA allows dynamic adjustment + * of memory attributes in the runtime. It contains a configurable amount of PMA + * entries implemented as CSRs to control the attributes of memory locations. + * + * Check if hardware supports PPMA + * + * @return true if PPMA is supported + * @return false if PPMA is not supported + */ +bool andes_sbi_probe_pma(void); + #endif /* _ANDES_PMA_H_ */ From patchwork Tue Jul 23 07:57:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Zong-You Xie X-Patchwork-Id: 1963644 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=pP493Yv3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WSqJP1bJfz1yXp for ; Tue, 23 Jul 2024 17:57:57 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6GsYRtcfUNLf5Sil6+oqLZXIIIBGEue1PTYuM0pAKmk=; b=pP493Yv34o4VwA azw8fDNeLepQxPV1IQk5IMxVV8zvuO0C2koPQC1HxRwxsm1u68YUGxlYZ9VwVOtQWPz1+0tGvimR4 tsHPi84u0k88EO62xKHCz7jJRoWSC6doZdLa53nJUGfIEuPeIokjxRwO3sYHtw/GvazkowrwRdubV oIL09hdpH7//rvggnoXTdN855V44erPL6sgySK/GoUoqS+9P4GceijogTmgF8RwirORNgSWROfPwb MSJrQ8ipBtToSsr5RpYNXLXnIzumvmSxkSYRFTyclhXzih1ty4jntlpGI6vXQ1oL6IsRgucT2q0B3 Szu3BXlW6AJ1yWo83Tbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWAP7-0000000BmXn-1Je3; Tue, 23 Jul 2024 07:57:49 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWAP3-0000000BmUO-3njo for opensbi@lists.infradead.org; Tue, 23 Jul 2024 07:57:48 +0000 Received: from mail.andestech.com (ATCPCS31.andestech.com [10.0.1.89]) by Atcsqr.andestech.com with ESMTPS id 46N7vZSp035910 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 23 Jul 2024 15:57:35 +0800 (+08) (envelope-from ben717@andestech.com) Received: from atctrx.andestech.com (10.0.15.190) by ATCPCS31.andestech.com (10.0.1.89) with Microsoft SMTP Server id 14.3.498.0; Tue, 23 Jul 2024 15:57:35 +0800 From: Ben Zong-You Xie To: CC: Ben Zong-You Xie Subject: [PATCH 3/4] platform: generic: andes: add a new Andes SBI call to set up a PMA entry Date: Tue, 23 Jul 2024 15:57:27 +0800 Message-ID: <20240723075728.587110-4-ben717@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240723075728.587110-1-ben717@andestech.com> References: <20240723075728.587110-1-ben717@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.190] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 46N7vZSp035910 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240723_005746_247852_6F5676A9 X-CRM114-Status: GOOD ( 18.50 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Implement a new Andes SBI call, which is to set up a NAPOT region with given memory attributes. Signed-off-by: Ben Zong-You Xie --- platform/generic/andes/andes_pma.c | 110 +++++++++++++++++++++ platform/generic/andes/andes_sbi.c | 9 +- platform/generic/include/andes/andes [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 TVD_RCVD_IP Message was received from an IP address 1.0 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Implement a new Andes SBI call, which is to set up a NAPOT region with given memory attributes. Signed-off-by: Ben Zong-You Xie Reviewed-by: Anup Patel --- platform/generic/andes/andes_pma.c | 110 +++++++++++++++++++++ platform/generic/andes/andes_sbi.c | 9 +- platform/generic/include/andes/andes_pma.h | 22 ++++- 3 files changed, 137 insertions(+), 4 deletions(-) diff --git a/platform/generic/andes/andes_pma.c b/platform/generic/andes/andes_pma.c index a884bf7..70039ca 100644 --- a/platform/generic/andes/andes_pma.c +++ b/platform/generic/andes/andes_pma.c @@ -94,6 +94,74 @@ static inline bool not_napot(unsigned long addr, unsigned long size) return ((size & (size - 1)) || (addr & (size - 1))); } +static inline bool is_pma_entry_disable(char pmaxcfg) +{ + return (pmaxcfg & ANDES_PMACFG_ETYP_MASK) == ANDES_PMACFG_ETYP_OFF ? + true : false; +} + +static char get_pmaxcfg(int entry_id) +{ + unsigned int pmacfg_addr; + unsigned long pmacfg_val; + char *pmaxcfg; + +#if __riscv_xlen == 64 + pmacfg_addr = CSR_PMACFG0 + ((entry_id / 8) ? 2 : 0); + pmacfg_val = andes_pma_read_num(pmacfg_addr); + pmaxcfg = (char *)&pmacfg_val + (entry_id % 8); +#elif __riscv_xlen == 32 + pmacfg_addr = CSR_PMACFG0 + (entry_id / 4); + pmacfg_val = andes_pma_read_num(pmacfg_addr); + pmaxcfg = (char *)&pmacfg_val + (entry_id % 4); +#else +#error "Unexpected __riscv_xlen" +#endif + return *pmaxcfg; +} + +static void decode_pmaaddrx(int entry_id, unsigned long *start, + unsigned long *size) +{ + unsigned long pmaaddr; + int k; + + /** + * Given $pmaaddr, let k = # of trailing 1s of $pmaaddr + * size = 2 ^ (k + 3) + * start = 4 * ($pmaaddr - (size / 8) + 1) + */ + pmaaddr = andes_pma_read_num(CSR_PMAADDR0 + entry_id); + k = sbi_ffz(pmaaddr); + *size = 1 << (k + 3); + *start = (pmaaddr - (1 << k) + 1) << 2; +} + +static bool has_pma_region_overlap(unsigned long start, unsigned long size) +{ + unsigned long _start, _size, _end, end; + char pmaxcfg; + + end = start + size - 1; + for (int i = 0; i < ANDES_MAX_PMA_REGIONS; i++) { + pmaxcfg = get_pmaxcfg(i); + if (is_pma_entry_disable(pmaxcfg)) + continue; + + decode_pmaaddrx(i, &_start, &_size); + _end = _start + _size - 1; + + if (MAX(start, _start) <= MIN(end, _end)) { + sbi_printf( + "ERROR %s(): %#lx ~ %#lx overlaps with PMA%d: %#lx ~ %#lx\n", + __func__, start, end, i, _start, _end); + return true; + } + } + + return false; +} + static unsigned long andes_pma_setup(const struct andes_pma_region *pma_region, unsigned int entry_id) { @@ -294,3 +362,45 @@ bool andes_sbi_probe_pma(void) { return (csr_read(CSR_MMSC_CFG) & MMSC_CFG_PPMA_MASK) ? true : false; } + +int andes_sbi_set_pma(unsigned long pa, unsigned long size, u8 flags) +{ + unsigned int entry_id; + unsigned long rc; + char pmaxcfg; + struct andes_pma_region region; + + if (!andes_sbi_probe_pma()) { + sbi_printf("ERROR %s(): Platform does not support PPMA.\n", + __func__); + return SBI_ERR_NOT_SUPPORTED; + } + + if (has_pma_region_overlap(pa, size)) + return SBI_ERR_INVALID_PARAM; + + for (entry_id = 0; entry_id < ANDES_MAX_PMA_REGIONS; entry_id++) { + pmaxcfg = get_pmaxcfg(entry_id); + if (is_pma_entry_disable(pmaxcfg)) { + region.pa = pa; + region.size = size; + region.flags = flags; + break; + } + } + + if (entry_id == ANDES_MAX_PMA_REGIONS) { + sbi_printf("ERROR %s(): All PMA entries have run out\n", + __func__); + return SBI_ERR_FAILED; + } + + rc = andes_pma_setup(®ion, entry_id); + if (rc == SBI_EINVAL) { + sbi_printf("ERROR %s(): Failed to set PMAADDR%d\n", + __func__, entry_id); + return SBI_ERR_FAILED; + } + + return SBI_SUCCESS; +} diff --git a/platform/generic/andes/andes_sbi.c b/platform/generic/andes/andes_sbi.c index a7ca4a5..0e4a43d 100644 --- a/platform/generic/andes/andes_sbi.c +++ b/platform/generic/andes/andes_sbi.c @@ -13,6 +13,7 @@ enum sbi_ext_andes_fid { SBI_EXT_ANDES_FID0 = 0, /* Reserved for future use */ SBI_EXT_ANDES_IOCP_SW_WORKAROUND, SBI_EXT_ANDES_PMA_PROBE, + SBI_EXT_ANDES_PMA_SET, }; static bool andes_cache_controllable(void) @@ -39,6 +40,7 @@ int andes_sbi_vendor_ext_provider(long funcid, struct sbi_ecall_return *out, const struct fdt_match *match) { + int ret = 0; switch (funcid) { case SBI_EXT_ANDES_IOCP_SW_WORKAROUND: out->value = andes_apply_iocp_sw_workaround(); @@ -46,10 +48,13 @@ int andes_sbi_vendor_ext_provider(long funcid, case SBI_EXT_ANDES_PMA_PROBE: out->value = andes_sbi_probe_pma(); break; + case SBI_EXT_ANDES_PMA_SET: + ret = andes_sbi_set_pma(regs->a0, regs->a1, regs->a2); + break; default: - return SBI_EINVAL; + ret = SBI_ENOTSUPP; } - return 0; + return ret; } diff --git a/platform/generic/include/andes/andes_pma.h b/platform/generic/include/andes/andes_pma.h index 147dca1..487d9bf 100644 --- a/platform/generic/include/andes/andes_pma.h +++ b/platform/generic/include/andes/andes_pma.h @@ -12,11 +12,15 @@ #define ANDES_PMA_GRANULARITY (1 << 12) +#define ANDES_PMACFG_ETYP_OFFSET 0 +#define ANDES_PMACFG_ETYP_MASK (3 << ANDES_PMACFG_ETYP_OFFSET) +#define ANDES_PMACFG_ETYP_OFF (0 << ANDES_PMACFG_ETYP_OFFSET) /* Naturally aligned power of 2 region */ -#define ANDES_PMACFG_ETYP_NAPOT 3 +#define ANDES_PMACFG_ETYP_NAPOT (3 << ANDES_PMACFG_ETYP_OFFSET) +#define ANDES_PMACFG_MTYP_OFFSET 2 /* Memory, Non-cacheable, Bufferable */ -#define ANDES_PMACFG_MTYP_MEM_NON_CACHE_BUF (3 << 2) +#define ANDES_PMACFG_MTYP_MEM_NON_CACHE_BUF (3 << ANDES_PMACFG_MTYP_OFFSET) /** * struct andes_pma_region - Describes PMA regions @@ -59,4 +63,18 @@ int andes_pma_setup_regions(const struct andes_pma_region *pma_regions, */ bool andes_sbi_probe_pma(void); +/** + * Set a NAPOT region with given memory attributes + * @param pa: Start address of the NAPOT region + * @param size: Size of the NAPOT region + * @param flags: Memory attributes set to the NAPOT region + * + * @return SBI_SUCCESS on success + * @return SBI_ERR_NOT_SUPPORTED if hardware does not support PPMA features + * @return SBI_ERR_INVALID_PARAM if the given region is overlapped with the + * region that has been set already + * @return SBI_ERR_FAILED if available entries have run out or setup fails + */ +int andes_sbi_set_pma(unsigned long pa, unsigned long size, u8 flags); + #endif /* _ANDES_PMA_H_ */ From patchwork Tue Jul 23 07:57:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Zong-You Xie X-Patchwork-Id: 1963643 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=yld12oVt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WSqJN34Pyz1yXp for ; Tue, 23 Jul 2024 17:57:56 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FvCLidsBr0LzIrZ+oUg520/FXqQugmkZUCoJXSBbGwo=; b=yld12oVtrpVJTx IJ9+tA3GWrNpdhKjBssvNVY5tgxYGsWiDK5ZvHYS1aDiBuASSnwd4xQG3HA+fx0ieGOh09zCd7xO7 x5XFc/LpB4yXCMnMvfO96pSXkF1kYbBQl8mtYwy7kLkxrc4LKVZUH2i3BkEFJAkDZJdOA+8jjFi02 hYGM4/j05BFYgim3L2dhNP5Zcr0xXOLBp/LEZ4x8tx2Hcs4HE03UNwV9vNx63bKNExp9/5uVjY7AN DjNfqSfUmIVcOJNP0uc7o7o6z3T7MYf8ZaWB2diWPSz60Am/iXi+EV/SOPMi02TDJ4CiOpIlMc/2w w8qRawRMDvBGWZfupwMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWAP7-0000000BmY8-3s7U; Tue, 23 Jul 2024 07:57:49 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWAP4-0000000BmVD-3Sms for opensbi@lists.infradead.org; Tue, 23 Jul 2024 07:57:48 +0000 Received: from mail.andestech.com (ATCPCS31.andestech.com [10.0.1.89]) by Atcsqr.andestech.com with ESMTPS id 46N7vaAt035929 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 23 Jul 2024 15:57:36 +0800 (+08) (envelope-from ben717@andestech.com) Received: from atctrx.andestech.com (10.0.15.190) by ATCPCS31.andestech.com (10.0.1.89) with Microsoft SMTP Server id 14.3.498.0; Tue, 23 Jul 2024 15:57:36 +0800 From: Ben Zong-You Xie To: CC: Ben Zong-You Xie Subject: [PATCH 4/4] platform: generic: andes: add a new Andes SBI call to free a PMA entry Date: Tue, 23 Jul 2024 15:57:28 +0800 Message-ID: <20240723075728.587110-5-ben717@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240723075728.587110-1-ben717@andestech.com> References: <20240723075728.587110-1-ben717@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.190] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 46N7vaAt035929 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240723_005747_337123_247FE483 X-CRM114-Status: GOOD ( 14.63 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add a new Andes SBI call to free a PMA entry, and reset the memory attributes for the corresponding NAPOT region. Signed-off-by: Ben Zong-You Xie --- platform/generic/andes/andes_pma.c | 65 ++++++++++++++++------ platform/generic/andes/andes_sbi.c | 4 ++ platform/generic/include/andes/andes [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 TVD_RCVD_IP Message was received from an IP address 1.0 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add a new Andes SBI call to free a PMA entry, and reset the memory attributes for the corresponding NAPOT region. Signed-off-by: Ben Zong-You Xie Reviewed-by: Anup Patel --- platform/generic/andes/andes_pma.c | 65 ++++++++++++++++------ platform/generic/andes/andes_sbi.c | 4 ++ platform/generic/include/andes/andes_pma.h | 9 +++ 3 files changed, 61 insertions(+), 17 deletions(-) diff --git a/platform/generic/andes/andes_pma.c b/platform/generic/andes/andes_pma.c index 70039ca..be61005 100644 --- a/platform/generic/andes/andes_pma.c +++ b/platform/generic/andes/andes_pma.c @@ -120,6 +120,27 @@ static char get_pmaxcfg(int entry_id) return *pmaxcfg; } +static void set_pmaxcfg(int entry_id, char flags) +{ + unsigned int pmacfg_addr; + unsigned long pmacfg_val; + char *pmaxcfg; + +#if __riscv_xlen == 64 + pmacfg_addr = CSR_PMACFG0 + ((entry_id / 8) ? 2 : 0); + pmacfg_val = andes_pma_read_num(pmacfg_addr); + pmaxcfg = (char *)&pmacfg_val + (entry_id % 8); +#elif __riscv_xlen == 32 + pmacfg_addr = CSR_PMACFG0 + (entry_id / 4); + pmacfg_val = andes_pma_read_num(pmacfg_addr); + pmaxcfg = (char *)&pmacfg_val + (entry_id % 4); +#else +#error "Unexpected __riscv_xlen" +#endif + *pmaxcfg = flags; + andes_pma_write_num(pmacfg_addr, pmacfg_val); +} + static void decode_pmaaddrx(int entry_id, unsigned long *start, unsigned long *size) { @@ -167,30 +188,14 @@ static unsigned long andes_pma_setup(const struct andes_pma_region *pma_region, { unsigned long size = pma_region->size; unsigned long addr = pma_region->pa; - unsigned int pma_cfg_addr; - unsigned long pmacfg_val; unsigned long pmaaddr; - char *pmaxcfg; /* Check for a 4KiB granularity NAPOT region*/ if (size < ANDES_PMA_GRANULARITY || not_napot(addr, size) || !(pma_region->flags & ANDES_PMACFG_ETYP_NAPOT)) return SBI_EINVAL; -#if __riscv_xlen == 64 - pma_cfg_addr = CSR_PMACFG0 + ((entry_id / 8) ? 2 : 0); - pmacfg_val = andes_pma_read_num(pma_cfg_addr); - pmaxcfg = (char *)&pmacfg_val + (entry_id % 8); -#elif __riscv_xlen == 32 - pma_cfg_addr = CSR_PMACFG0 + (entry_id / 4); - pmacfg_val = andes_pma_read_num(pma_cfg_addr); - pmaxcfg = (char *)&pmacfg_val + (entry_id % 4); -#else -#error "Unexpected __riscv_xlen" -#endif - *pmaxcfg = pma_region->flags; - - andes_pma_write_num(pma_cfg_addr, pmacfg_val); + set_pmaxcfg(entry_id, pma_region->flags); pmaaddr = (addr >> 2) + (size >> 3) - 1; @@ -404,3 +409,29 @@ int andes_sbi_set_pma(unsigned long pa, unsigned long size, u8 flags) return SBI_SUCCESS; } + +int andes_sbi_free_pma(unsigned long pa) +{ + unsigned long start, size; + char pmaxcfg; + + for (int i = 0; i < ANDES_MAX_PMA_REGIONS; i++) { + pmaxcfg = get_pmaxcfg(i); + if (is_pma_entry_disable(pmaxcfg)) + continue; + + decode_pmaaddrx(i, &start, &size); + if (start != pa) + continue; + + set_pmaxcfg(i, ANDES_PMACFG_ETYP_OFF); + andes_pma_write_num(CSR_PMAADDR0 + i, 0); + + return SBI_SUCCESS; + } + + sbi_printf("ERROR %s(): Failed to find the entry with PA %#lx\n", + __func__, pa); + + return SBI_ERR_FAILED; +} diff --git a/platform/generic/andes/andes_sbi.c b/platform/generic/andes/andes_sbi.c index 0e4a43d..0e1e59e 100644 --- a/platform/generic/andes/andes_sbi.c +++ b/platform/generic/andes/andes_sbi.c @@ -14,6 +14,7 @@ enum sbi_ext_andes_fid { SBI_EXT_ANDES_IOCP_SW_WORKAROUND, SBI_EXT_ANDES_PMA_PROBE, SBI_EXT_ANDES_PMA_SET, + SBI_EXT_ANDES_PMA_FREE, }; static bool andes_cache_controllable(void) @@ -51,6 +52,9 @@ int andes_sbi_vendor_ext_provider(long funcid, case SBI_EXT_ANDES_PMA_SET: ret = andes_sbi_set_pma(regs->a0, regs->a1, regs->a2); break; + case SBI_EXT_ANDES_PMA_FREE: + ret = andes_sbi_free_pma(regs->a0); + break; default: ret = SBI_ENOTSUPP; diff --git a/platform/generic/include/andes/andes_pma.h b/platform/generic/include/andes/andes_pma.h index 487d9bf..e2d5279 100644 --- a/platform/generic/include/andes/andes_pma.h +++ b/platform/generic/include/andes/andes_pma.h @@ -77,4 +77,13 @@ bool andes_sbi_probe_pma(void); */ int andes_sbi_set_pma(unsigned long pa, unsigned long size, u8 flags); +/** + * Reset the memory attribute of a NAPOT region + * @param pa Start address of the NAPOT region + * + * @return SBI_SUCCESS on success + * @return SBI_ERR_FAILED if the given region is not set before + */ +int andes_sbi_free_pma(unsigned long pa); + #endif /* _ANDES_PMA_H_ */