OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Chao-ying Fu <icebergfu@gmail.com>
To: opensbi@lists.infradead.org
Cc: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
Subject: [PATCH v5 10/10] Fix PMA init for MMIO regions
Date: Mon, 19 May 2025 14:58:47 -0700	[thread overview]
Message-ID: <20250519215848.27569-11-cfu@mips.com> (raw)
In-Reply-To: <CAAhSdy2jObwq5SUymwVmwMhcQ_h0-4OJuhwitgcVN2gPq2B=XQ@mail.gmail.com>

From: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>

Convey MMIO flag as specified by SBI_DOMAIN_MEMREGION_MMIO
to the pma_set(); use this flag to decide upon memory cacheability

Introduce non-architecture bit PMP_MMIO for this new flag, have it
out of valid bit mask for the PMPCFG register to avoid side effects

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 include/sbi/riscv_asm.h |  2 ++
 lib/sbi/riscv_asm.c     | 10 +++-------
 lib/sbi/sbi_hart.c      | 13 +++++++++++++
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/include/sbi/riscv_asm.h b/include/sbi/riscv_asm.h
index ef48dc8..1bb2be7 100644
--- a/include/sbi/riscv_asm.h
+++ b/include/sbi/riscv_asm.h
@@ -215,6 +215,8 @@ int pmp_disable(unsigned int n);
 /* Check if the matching field is set */
 int is_pmp_entry_mapped(unsigned long entry);
 
+#define PMP_MMIO   _UL(0x100)
+
 int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
 	    unsigned long log2len);
 
diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c
index 7eb02cf..9f31c3e 100644
--- a/lib/sbi/riscv_asm.c
+++ b/lib/sbi/riscv_asm.c
@@ -311,8 +311,7 @@ int is_pmp_entry_mapped(unsigned long entry)
 }
 
 #ifdef CONFIG_PLATFORM_MIPS_P8700
-extern unsigned long _fw_start;
-static void pma_set(unsigned int n, unsigned long addr)
+static void pma_set(unsigned int n, unsigned long prot, unsigned long addr)
 {
 	int pmacfg_csr, pmacfg_shift;
 	unsigned long cfgmask;
@@ -324,10 +323,7 @@ static void pma_set(unsigned int n, unsigned long addr)
 
 	/* Read pmacfg to change cacheability */
 	pmacfg  = (csr_read_num(pmacfg_csr) & cfgmask);
-	if (addr >= (unsigned long)&_fw_start)
-		cca = CCA_CACHE_ENABLE | PMA_SPECULATION;
-	else
-		cca = CCA_CACHE_DISABLE;
+	cca = (prot & PMP_MMIO) ? CCA_CACHE_DISABLE : CCA_CACHE_ENABLE | PMA_SPECULATION;
 	pmacfg |= ((cca << pmacfg_shift) & ~cfgmask);
 	csr_write_num(pmacfg_csr, pmacfg);
 }
@@ -345,7 +341,7 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
 		return SBI_EINVAL;
 
 #ifdef CONFIG_PLATFORM_MIPS_P8700
-	pma_set(n, addr);
+	pma_set(n, prot, addr);
 #endif
 
 	/* calculate PMP register and offset */
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index fc4925b..ab56890 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -361,6 +361,13 @@ static unsigned int sbi_hart_get_smepmp_flags(struct sbi_scratch *scratch,
 			pmp_flags |= PMP_X;
 	}
 
+	/*
+	 * indicate whether it is MMIO, to be evaluated by code,
+	 * out of pmpcfg mask
+	 */
+	if (reg->flags & SBI_DOMAIN_MEMREGION_MMIO)
+		pmp_flags |= PMP_MMIO;
+
 	return pmp_flags;
 }
 
@@ -489,6 +496,12 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch,
 			pmp_flags |= PMP_W;
 		if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE)
 			pmp_flags |= PMP_X;
+		/*
+		 * indicate whether it is MMIO, to be evaluated by code,
+		 * out of pmpcfg mask
+		 */
+		if (reg->flags & SBI_DOMAIN_MEMREGION_MMIO)
+			pmp_flags |= PMP_MMIO;
 
 		pmp_addr = reg->base >> PMP_SHIFT;
 		if (pmp_log2gran <= reg->order && pmp_addr < pmp_addr_max) {
-- 
2.47.1


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

  parent reply	other threads:[~2025-05-19 21:59 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-17 22:34 [PATCH] platform: generic: mips: add P8700 Chao-ying Fu
2025-02-12 12:27 ` Anup Patel
2025-02-26  0:53   ` [PATCH v2 01/11] " Chao-ying Fu
2025-03-28  4:45     ` Anup Patel
2025-02-26  0:53   ` [PATCH v2 02/11] platform: generic: mips: add header files Chao-ying Fu
2025-03-28  4:47     ` Anup Patel
2025-02-26  0:53   ` [PATCH v2 03/11] platform: generic: mips: add mips-cm header file Chao-ying Fu
2025-03-28  4:48     ` Anup Patel
2025-02-26  0:53   ` [PATCH v2 04/11] platform: generic: mips: add custom exception handler Chao-ying Fu
2025-03-28  4:53     ` Anup Patel
2025-04-08  2:49       ` Chao-ying Fu
2025-02-26  0:53   ` [PATCH v2 05/11] platform: generic: mips: add extra scratch space Chao-ying Fu
2025-03-28  4:56     ` Anup Patel
2025-02-26  0:53   ` [PATCH v2 06/11] platform: generic: mips: add an entry function Chao-ying Fu
2025-03-28  5:00     ` Anup Patel
2025-02-26  0:53   ` [PATCH v2 07/11] platform: generic: mips: add the platform file Chao-ying Fu
2025-02-26  0:53   ` [PATCH v2 08/11] platform: generic: mips: add a dts file Chao-ying Fu
2025-02-26  0:53   ` [PATCH v2 09/11] platform: generic: mips: add objects.mk Chao-ying Fu
2025-02-26  0:53   ` [PATCH v2 10/11] Change to jump to mips_cps_core_entry Chao-ying Fu
2025-02-26  0:53   ` [PATCH v2 11/11] Initialize MIPS custom PMA registers Chao-ying Fu
2025-04-10 22:45   ` [PATCH v3 0/9] *** Add MIPS P8700 platform *** Chao-ying Fu
2025-04-10 22:45   ` [PATCH v3 1/9] platform: generic: mips: add P8700 Chao-ying Fu
2025-04-10 22:45   ` [PATCH v3 2/9] platform: generic: mips: add header files Chao-ying Fu
2025-04-10 22:45   ` [PATCH v3 3/9] platform: generic: mips: add an entry function Chao-ying Fu
2025-04-10 22:45   ` [PATCH v3 4/9] platform: generic: add nanscent_init to platform_override Chao-ying Fu
2025-04-10 22:45   ` [PATCH v3 5/9] platform: generic: mips: add the platform file Chao-ying Fu
2025-04-10 22:45   ` [PATCH v3 6/9] lib: Emulate amo instructions Chao-ying Fu
2025-04-10 22:45   ` [PATCH v3 7/9] platform: generic: mips: add a dts file Chao-ying Fu
2025-04-10 22:45   ` [PATCH v3 8/9] platform: generic: mips: add objects.mk Chao-ying Fu
2025-04-10 22:45   ` [PATCH v3 9/9] Initialize MIPS custom PMA registers Chao-ying Fu
2025-04-29 23:29   ` [PATCH v4 0/8] *** Add MIPS P8700 platform *** Chao-ying Fu
2025-05-19 12:16     ` Anup Patel
2025-05-19 18:33       ` Chao-ying Fu
2025-05-19 21:52         ` Chao-ying Fu
2025-04-29 23:29   ` [PATCH v4 1/8] platform: generic: mips: add P8700 Chao-ying Fu
2025-04-29 23:29   ` [PATCH v4 2/8] platform: generic: mips: add header files Chao-ying Fu
2025-04-29 23:29   ` [PATCH v4 3/8] platform: generic: mips: add an entry function Chao-ying Fu
2025-04-29 23:29   ` [PATCH v4 4/8] platform: generic: mips: add the platform file Chao-ying Fu
2025-04-29 23:29   ` [PATCH v4 5/8] lib: Emulate amo instructions Chao-ying Fu
2025-05-19 12:14     ` Anup Patel
2025-04-29 23:29   ` [PATCH v4 6/8] platform: generic: mips: add a dts file Chao-ying Fu
2025-04-29 23:29   ` [PATCH v4 7/8] platform: generic: mips: add objects.mk Chao-ying Fu
2025-04-29 23:29   ` [PATCH v4 8/8] Initialize MIPS custom PMA registers Chao-ying Fu
2025-05-19 21:58   ` [PATCH v5 00/10] *** Add MIPS P8700 Platform *** Chao-ying Fu
2025-05-20  5:18     ` Anup Patel
2025-05-19 21:58   ` [PATCH v5 01/10] platform: generic: mips: add P8700 Chao-ying Fu
2025-05-19 21:58   ` [PATCH v5 02/10] platform: generic: mips: add header files Chao-ying Fu
2025-05-19 21:58   ` [PATCH v5 03/10] platform: generic: mips: add an entry function Chao-ying Fu
2025-05-20  5:29     ` Anup Patel
2025-05-22 20:50       ` Chao-ying Fu
2025-05-19 21:58   ` [PATCH v5 04/10] platform: generic: mips: add the platform file Chao-ying Fu
2025-05-19 21:58   ` [PATCH v5 05/10] platform: generic: mips: add a dts file Chao-ying Fu
2025-05-20  5:31     ` Anup Patel
2025-05-22 20:52       ` Chao-ying Fu
2025-05-19 21:58   ` [PATCH v5 06/10] platform: generic: mips: add objects.mk Chao-ying Fu
2025-05-19 21:58   ` [PATCH v5 07/10] Initialize MIPS custom PMA registers Chao-ying Fu
2025-05-20  5:08     ` Anup Patel
2025-05-22 20:47       ` Chao-ying Fu
2025-05-19 21:58   ` [PATCH v5 08/10] devices to use MMIO memory Chao-ying Fu
2025-05-19 21:58   ` [PATCH v5 09/10] platform: generic: mips: add mmio to allmem in the dts file Chao-ying Fu
2025-05-19 21:58   ` Chao-ying Fu [this message]
2025-05-22 21:21   ` [MIPS P8700 v6 0/7] Add MIPS P8700 support to generic platform Chao-ying Fu
2025-06-14 16:18     ` Anup Patel
2025-05-22 21:21   ` [MIPS P8700 v6 1/7] platform: generic: mips: add P8700 Chao-ying Fu
2025-05-22 21:21   ` [MIPS P8700 v6 2/7] platform: generic: mips: add header files Chao-ying Fu
2025-05-22 21:21   ` [MIPS P8700 v6 3/7] platform: generic: mips: add the platform file Chao-ying Fu
2025-05-22 21:21   ` [MIPS P8700 v6 4/7] platform: generic: mips: add objects.mk Chao-ying Fu
2025-05-22 21:21   ` [MIPS P8700 v6 5/7] devices to use MMIO memory Chao-ying Fu
2025-05-22 21:21   ` [MIPS P8700 v6 6/7] Convey MMIO flag as specified by SBI_DOMAIN_MEMREGION_MMIO Chao-ying Fu
2025-05-22 21:21   ` [MIPS P8700 v6 7/7] lib: sbi_platform: Add the platform pma_set function to set up cacheability Chao-ying Fu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250519215848.27569-11-cfu@mips.com \
    --to=icebergfu@gmail.com \
    --cc=opensbi@lists.infradead.org \
    --cc=vladimir.kondratiev@mobileye.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox