From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 2/4] ARM: mmu64: define early_remap_range for mmu_early_enable usage
Date: Fri, 26 May 2023 08:33:52 +0200 [thread overview]
Message-ID: <20230526063354.1145474-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230526063354.1145474-1-a.fatoum@pengutronix.de>
Adding a new dma_inv_range/dma_flush_range into arch_remap_range before
MMU is enabled hangs, so let's define a new early_remap_range that should
always be safe to call while MMU is disabled. This is to prepare doing
cache maintenance in regular arch_remap_range in a later commit.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/cpu/mmu_64.c | 39 ++++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 13 deletions(-)
diff --git a/arch/arm/cpu/mmu_64.c b/arch/arm/cpu/mmu_64.c
index 1d5a5355c6be..940e0e914c43 100644
--- a/arch/arm/cpu/mmu_64.c
+++ b/arch/arm/cpu/mmu_64.c
@@ -159,23 +159,36 @@ static void create_sections(uint64_t virt, uint64_t phys, uint64_t size,
tlb_invalidate();
}
-int arch_remap_range(void *virt_addr, phys_addr_t phys_addr, size_t size, unsigned flags)
+static unsigned long get_pte_attrs(unsigned flags)
{
- unsigned long attrs;
-
switch (flags) {
case MAP_CACHED:
- attrs = CACHED_MEM;
- break;
+ return CACHED_MEM;
case MAP_UNCACHED:
- attrs = attrs_uncached_mem();
- break;
+ return attrs_uncached_mem();
case MAP_FAULT:
- attrs = 0x0;
- break;
+ return 0x0;
default:
- return -EINVAL;
+ return ~0UL;
}
+}
+
+static void early_remap_range(uint64_t addr, size_t size, unsigned flags)
+{
+ unsigned long attrs = get_pte_attrs(flags);
+
+ if (WARN_ON(attrs == ~0UL))
+ return;
+
+ create_sections(addr, addr, size, attrs);
+}
+
+int arch_remap_range(void *virt_addr, phys_addr_t phys_addr, size_t size, unsigned flags)
+{
+ unsigned long attrs = get_pte_attrs(flags);
+
+ if (attrs == ~0UL)
+ return -EINVAL;
create_sections((uint64_t)virt_addr, phys_addr, (uint64_t)size, attrs);
return 0;
@@ -269,9 +282,9 @@ void mmu_early_enable(unsigned long membase, unsigned long memsize)
memset((void *)ttb, 0, GRANULE_SIZE);
- remap_range(0, 1UL << (BITS_PER_VA - 1), MAP_UNCACHED);
- remap_range((void *)membase, memsize - OPTEE_SIZE, MAP_CACHED);
- remap_range((void *)membase + memsize - OPTEE_SIZE, OPTEE_SIZE, MAP_FAULT);
+ early_remap_range(0, 1UL << (BITS_PER_VA - 1), MAP_UNCACHED);
+ early_remap_range(membase, memsize - OPTEE_SIZE, MAP_CACHED);
+ early_remap_range(membase + memsize - OPTEE_SIZE, OPTEE_SIZE, MAP_FAULT);
mmu_enable();
}
--
2.39.2
next prev parent reply other threads:[~2023-05-26 6:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-26 6:33 [PATCH master 1/4] ARM: mmu64: request TTB region Ahmad Fatoum
2023-05-26 6:33 ` Ahmad Fatoum [this message]
2023-05-26 6:33 ` [PATCH master 3/4] ARM: mmu32: define early_remap_range for mmu_early_enable usage Ahmad Fatoum
2023-05-26 6:33 ` [PATCH master 4/4] ARM: mmu: invalidate when mapping range uncached Ahmad Fatoum
2023-05-26 12:49 ` Ahmad Fatoum
2023-05-30 10:26 ` [PATCH master 1/4] ARM: mmu64: request TTB region Sascha Hauer
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=20230526063354.1145474-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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