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_ */