[PATCH v2 12/18] ARM64: mmu: add dynamic optee memory mapping support
Marco Felsch
m.felsch at pengutronix.de
Thu Jan 18 01:13:43 PST 2024
On 24-01-17, Sascha Hauer wrote:
> On Tue, Jan 16, 2024 at 06:07:32PM +0100, Marco Felsch wrote:
> > Use the dynamic optee memory base address for the early mapping if
> > possible and fallback to the static mapping if the query failed.
> >
> > Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
> > ---
> > arch/arm/cpu/mmu_64.c | 14 ++++++++++++--
> > arch/arm/mach-imx/esdctl.c | 4 ++++
> > common/Makefile | 2 +-
> > 3 files changed, 17 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/arm/cpu/mmu_64.c b/arch/arm/cpu/mmu_64.c
> > index 84f45bc2c3c1..27fd15ea1233 100644
> > --- a/arch/arm/cpu/mmu_64.c
> > +++ b/arch/arm/cpu/mmu_64.c
> > @@ -20,6 +20,7 @@
> > #include <memory.h>
> > #include <asm/system_info.h>
> > #include <linux/pagemap.h>
> > +#include <tee/optee.h>
> >
> > #include "mmu_64.h"
> >
> > @@ -310,6 +311,7 @@ static void init_range(size_t total_level0_tables)
> > void mmu_early_enable(unsigned long membase, unsigned long memsize)
> > {
> > int el;
> > + u64 optee_membase;
> > unsigned long ttb = arm_mem_ttb(membase + memsize);
> >
> > pr_debug("enabling MMU, ttb @ 0x%08lx\n", ttb);
> > @@ -326,8 +328,16 @@ void mmu_early_enable(unsigned long membase, unsigned long memsize)
> > * Set 1:1 mapping of VA->PA. So to cover the full 1TB range we need 2 tables.
> > */
> > init_range(2);
> > - early_remap_range(membase, memsize - OPTEE_SIZE, MAP_CACHED);
> > - early_remap_range(membase + memsize - OPTEE_SIZE, OPTEE_SIZE, MAP_FAULT);
> > +
> > + if (optee_get_membase(&optee_membase)) {
> > + /* Fallback and place OP-TEE at the memory end region */
> > + early_remap_range(membase, memsize - OPTEE_SIZE, MAP_CACHED);
> > + early_remap_range(membase + memsize - OPTEE_SIZE, OPTEE_SIZE, MAP_FAULT);
> > + } else {
> > + early_remap_range(membase, memsize, MAP_CACHED);
> > + early_remap_range(optee_membase, OPTEE_SIZE, MAP_FAULT);
> > + }
>
> You could replace the above with:
>
> early_remap_range(membase, memsize, MAP_CACHED);
>
> optee_membase = membase + memsize - OPTEE_SIZE;
> optee_get_membase(&optee_membase);
> early_remap_range(optee_membase, OPTEE_SIZE, MAP_FAULT);
Nice catch, thanks a lot. How about:
early_remap_range(membase, memsize, MAP_CACHED);
if (optee_get_membase(&optee_membase))
optee_membase = membase + memsize - OPTEE_SIZE;
early_remap_range(optee_membase, OPTEE_SIZE, MAP_FAULT);
Regards,
Marco
>
> Sascha
>
> --
> Pengutronix e.K. | |
> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
More information about the barebox
mailing list