From patchwork Wed Sep 11 15:31:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 173618 Delivered-To: patch@linaro.org Received: by 2002:ac9:19ad:0:0:0:0:0 with SMTP id d45csp942527oce; Wed, 11 Sep 2019 08:33:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwtGWn2z2tj2o2FR/xBZkHFeH3zLcHBFP3178ONvQHDkYqTp3QceFc1X2pIZSEdEfdxB0AM X-Received: by 2002:a9d:3c1:: with SMTP id f59mr31785479otf.300.1568215989023; Wed, 11 Sep 2019 08:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568215989; cv=none; d=google.com; s=arc-20160816; b=gKXaTGU4xyZ0vAVz3YLe5kQQ6MZkRx+spIZFkr5oKa4bl1UMJFSAzRiOj7UFkhKzHc NXYSgAd2PAKd83EwvLA0uT9uiVG2ry91G1HHrvst2SBa15aiyK2NRCx9N7LEjP7oxpe7 6VwouiJjn126c9WwqmWtPFoTpx19tMHy6QvzmscNQ8ksNpUid03TFQdKo7WMUxqL7lAF xdwQBzou4Zhk1bO35X2tIRdHWhXEf/hO4YWu97hlsoS8ps0ZX0OX2UYcQ4fWNdh2o6Wz CRsmBANzN1Zh+3pO9u5jJhoNH5kYG0fjRNlTlA+aSLA0OasFRHCEXwptxmbo+bs9/g48 uWxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:message-id:date:to:from; bh=TINuXD2/QEGFFBqxjTrf9wGNKAZSOTxQ4zqZXSIfNoo=; b=IZItpRMAq/baCj6jcCgfMuDP4RMPdWM8b78mwAeMwmjYL317URSMHiGa3pPToz+QTP lETbGKeGONjxP7tn7Mto35N4UD81a4SkEVBuocTL3ypqqUqt6dswwZPJUkd8R4hMNdB5 YOiIdl8TC9u5qUJkLdtvdQ+0C3TGjt+tE5BxU6Me84FnQjqZpH4/fYpslOXe7uxTVP97 wE9m3A0MB4P/Fw7K6ozCekvFKZjnIzvAqoAEU3qro+uvyPF46tDqWG1MoX6G8Ntmlfnp QIz50tXZkpAgWjO59bYQetkC0kJEvEjdbCb9au87CC1jAPcBoJV5mpsm8KZZJpQ3IFlB kM1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id l7si9984822oif.41.2019.09.11.08.33.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Sep 2019 08:33:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i84at-0003z5-Pk; Wed, 11 Sep 2019 15:31:43 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i84as-0003ys-5A for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 15:31:42 +0000 X-Inumbo-ID: 4027cb72-d4a9-11e9-a337-bc764e2007e4 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 4027cb72-d4a9-11e9-a337-bc764e2007e4; Wed, 11 Sep 2019 15:31:40 +0000 (UTC) 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 136AD28; Wed, 11 Sep 2019 08:31:40 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 60E4A3F67D; Wed, 11 Sep 2019 08:31:39 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 11 Sep 2019 16:31:34 +0100 Message-Id: <20190911153134.20402-1-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 Subject: [Xen-devel] [PATCH] xen/arm: setup: Relocate the Device-Tree later on in the boot X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, the Device-Tree is relocated into xenheap while setting up the memory subsystem. This is actually not necessary because the early mapping is still present and we don't require the virtual address to be stable until unflatting the Device-Tree. So the relocation can safely be moved after the memory subsystem is fully setup. This has the nice advantage to make the relocation common and let the xenheap allocator decides where to put it. Lastly, the device-tree is not going to be used for ACPI system. So there are no need to relocate it and can just be discarded. Signed-off-by: Julien Grall Reviewed-by: Volodymyr Babchuk Acked-by: Stefano Stabellini --- xen/arch/arm/setup.c | 58 ++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 1b303bde34..ebbfad94e4 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -399,6 +399,19 @@ void __init discard_initial_modules(void) remove_early_mappings(); } +/* Relocate the FDT in Xen heap */ +static void * __init relocate_fdt(paddr_t dtb_paddr, size_t dtb_size) +{ + void *fdt = xmalloc_bytes(dtb_size); + + if ( !fdt ) + panic("Unable to allocate memory for relocating the Device-Tree.\n"); + + copy_from_paddr(fdt, dtb_paddr, dtb_size); + + return fdt; +} + #ifdef CONFIG_ARM_32 /* * Returns the end address of the highest region in the range s..e @@ -572,16 +585,13 @@ static void __init init_pdx(void) } #ifdef CONFIG_ARM_32 -static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size) +static void __init setup_mm(void) { paddr_t ram_start, ram_end, ram_size; paddr_t s, e; unsigned long ram_pages; unsigned long heap_pages, xenheap_pages, domheap_pages; - unsigned long dtb_pages; - unsigned long boot_mfn_start, boot_mfn_end; int i; - void *fdt; const uint32_t ctr = READ_CP32(CTR); if ( !bootinfo.mem.nr_banks ) @@ -655,21 +665,6 @@ static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size) setup_xenheap_mappings((e >> PAGE_SHIFT) - xenheap_pages, xenheap_pages); - /* - * Need a single mapped page for populating bootmem_region_list - * and enough mapped pages for copying the DTB. - */ - dtb_pages = (dtb_size + PAGE_SIZE-1) >> PAGE_SHIFT; - boot_mfn_start = mfn_x(xenheap_mfn_end) - dtb_pages - 1; - boot_mfn_end = mfn_x(xenheap_mfn_end); - - init_boot_pages(pfn_to_paddr(boot_mfn_start), pfn_to_paddr(boot_mfn_end)); - - /* Copy the DTB. */ - fdt = mfn_to_virt(mfn_x(alloc_boot_pages(dtb_pages, 1))); - copy_from_paddr(fdt, dtb_paddr, dtb_size); - device_tree_flattened = fdt; - /* Add non-xenheap memory */ for ( i = 0; i < bootinfo.mem.nr_banks; i++ ) { @@ -713,20 +708,17 @@ static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size) setup_frametable_mappings(ram_start, ram_end); max_page = PFN_DOWN(ram_end); - /* Add xenheap memory that was not already added to the boot - allocator. */ + /* Add xenheap memory that was not already added to the boot allocator. */ init_xenheap_pages(mfn_to_maddr(xenheap_mfn_start), - pfn_to_paddr(boot_mfn_start)); + mfn_to_maddr(xenheap_mfn_end)); } #else /* CONFIG_ARM_64 */ -static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size) +static void __init setup_mm(void) { paddr_t ram_start = ~0; paddr_t ram_end = 0; paddr_t ram_size = 0; int bank; - unsigned long dtb_pages; - void *fdt; init_pdx(); @@ -770,16 +762,6 @@ static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size) xenheap_mfn_start = maddr_to_mfn(ram_start); xenheap_mfn_end = maddr_to_mfn(ram_end); - /* - * Need enough mapped pages for copying the DTB. - */ - dtb_pages = (dtb_size + PAGE_SIZE-1) >> PAGE_SHIFT; - - /* Copy the DTB. */ - fdt = mfn_to_virt(mfn_x(alloc_boot_pages(dtb_pages, 1))); - copy_from_paddr(fdt, dtb_paddr, dtb_size); - device_tree_flattened = fdt; - setup_frametable_mappings(ram_start, ram_end); max_page = PFN_DOWN(ram_end); } @@ -838,7 +820,7 @@ void __init start_xen(unsigned long boot_phys_offset, printk("Command line: %s\n", cmdline); cmdline_parse(cmdline); - setup_mm(fdt_paddr, fdt_size); + setup_mm(); /* Parse the ACPI tables for possible boot-time configuration */ acpi_boot_table_init(); @@ -856,10 +838,14 @@ void __init start_xen(unsigned long boot_phys_offset, if ( acpi_disabled ) { printk("Booting using Device Tree\n"); + device_tree_flattened = relocate_fdt(fdt_paddr, fdt_size); dt_unflatten_host_device_tree(); } else + { printk("Booting using ACPI\n"); + device_tree_flattened = NULL; + } init_IRQ();