From nobody Thu Oct 23 00:47:03 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1687750888548382.12956133821865; Sun, 25 Jun 2023 20:41:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.555110.866923 (Exim 4.92) (envelope-from ) id 1qDd5z-0007B1-Vv; Mon, 26 Jun 2023 03:40:55 +0000 Received: by outflank-mailman (output) from mailman id 555110.866923; Mon, 26 Jun 2023 03:40:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qDd5z-00074p-3s; Mon, 26 Jun 2023 03:40:55 +0000 Received: by outflank-mailman (input) for mailman id 555110; Mon, 26 Jun 2023 03:40:51 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qDd21-0007ej-Q9 for xen-devel@lists.xenproject.org; Mon, 26 Jun 2023 03:36:49 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id ae818a65-13d2-11ee-b237-6b7b168915f2; Mon, 26 Jun 2023 05:36:48 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7A7131FB; Sun, 25 Jun 2023 20:37:32 -0700 (PDT) Received: from a011292.shanghai.arm.com (a011292.shanghai.arm.com [10.169.190.94]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D0CD03F64C; Sun, 25 Jun 2023 20:36:45 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ae818a65-13d2-11ee-b237-6b7b168915f2 From: Penny Zheng To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Penny Zheng , Wei Chen Subject: [PATCH v3 32/52] xen/mpu: implement MPU version of setup_mm in mpu/setup.c Date: Mon, 26 Jun 2023 11:34:23 +0800 Message-Id: <20230626033443.2943270-33-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230626033443.2943270-1-Penny.Zheng@arm.com> References: <20230626033443.2943270-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1687750890212100001 Content-Type: text/plain; charset="utf-8" In MPU system, resource, like Xenheap, must be statically configured to meet the requirement of static system with expected behavior. Then, in MPU version of setup_mm, we introduce setup_staticheap_mappings to map fixed MPU memory region for static Xenheap. Signed-off-by: Penny Zheng Signed-off-by: Wei Chen --- v3: - move the changes to mpu/setup.c --- xen/arch/arm/Makefile | 1 + xen/arch/arm/include/asm/mpu/mm.h | 1 + xen/arch/arm/mpu/mm.c | 27 ++++++++++++ xen/arch/arm/mpu/setup.c | 70 +++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 xen/arch/arm/mpu/setup.c diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 3bd193ee32..5f6ee817ad 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -42,6 +42,7 @@ obj-y +=3D mmu/setup.o obj-y +=3D mmu/p2m.o else obj-y +=3D mpu/mm.o +obj-y +=3D mpu/setup.o endif obj-y +=3D mm.o obj-y +=3D monitor.o diff --git a/xen/arch/arm/include/asm/mpu/mm.h b/xen/arch/arm/include/asm/m= pu/mm.h index eec572ecfc..e26bd4f975 100644 --- a/xen/arch/arm/include/asm/mpu/mm.h +++ b/xen/arch/arm/include/asm/mpu/mm.h @@ -3,6 +3,7 @@ #define __ARCH_ARM_MM_MPU__ =20 extern int xen_mpumap_update(paddr_t base, paddr_t limit, unsigned int fla= gs); +extern void setup_staticheap_mappings(void); =20 #endif /* __ARCH_ARM_MM_MPU__ */ =20 diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c index f4ce19d36a..7bd5609102 100644 --- a/xen/arch/arm/mpu/mm.c +++ b/xen/arch/arm/mpu/mm.c @@ -22,8 +22,10 @@ #include #include #include +#include #include #include +#include =20 #ifdef NDEBUG static inline void __attribute__ ((__format__ (__printf__, 1, 2))) @@ -486,6 +488,31 @@ int xen_mpumap_update(paddr_t base, paddr_t limit, uns= igned int flags) return rc; } =20 +/* + * Heap must be statically configured in Device Tree through + * "xen,static-heap" in MPU system. + */ +void __init setup_staticheap_mappings(void) +{ + unsigned int bank =3D 0; + + for ( ; bank < bootinfo.reserved_mem.nr_banks; bank++ ) + { + if ( bootinfo.reserved_mem.bank[bank].type =3D=3D MEMBANK_STATIC_H= EAP ) + { + paddr_t bank_start =3D round_pgup( + bootinfo.reserved_mem.bank[bank].start); + paddr_t bank_size =3D round_pgdown( + bootinfo.reserved_mem.bank[bank].size); + paddr_t bank_end =3D bank_start + bank_size; + + /* Map static heap with fixed MPU memory region */ + if ( xen_mpumap_update(bank_start, bank_end, PAGE_HYPERVISOR) ) + panic("mpu: failed to map static heap\n"); + } + } +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/mpu/setup.c b/xen/arch/arm/mpu/setup.c new file mode 100644 index 0000000000..31f412957c --- /dev/null +++ b/xen/arch/arm/mpu/setup.c @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * xen/arch/arm/mpu/setup.c + * + * Early bringup code for an Armv8-R with virt extensions. + * + * Copyright (C) 2023 Arm Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +void __init setup_mm(void) +{ + paddr_t ram_start =3D ~0, ram_end =3D 0, ram_size =3D 0; + unsigned int bank; + + if ( !bootinfo.mem.nr_banks ) + panic("No memory bank\n"); + + init_pdx(); + + populate_boot_allocator(); + + total_pages =3D 0; + for ( bank =3D 0 ; bank < bootinfo.mem.nr_banks; bank++ ) + { + paddr_t bank_start =3D round_pgup(bootinfo.mem.bank[bank].start); + paddr_t bank_size =3D bootinfo.mem.bank[bank].size; + paddr_t bank_end =3D round_pgdown(bank_start + bank_size); + + ram_size =3D ram_size + bank_size; + ram_start =3D min(ram_start, bank_start); + ram_end =3D max(ram_end, bank_end); + } + + setup_staticheap_mappings(); + + total_pages +=3D ram_size >> PAGE_SHIFT; + max_page =3D PFN_DOWN(ram_end); + + setup_frametable_mappings(ram_start, ram_end); + + init_staticmem_pages(); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.25.1