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: 11141391 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B58E1599 for ; Wed, 11 Sep 2019 15:33:28 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 50A2F2084D for ; Wed, 11 Sep 2019 15:33:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 50A2F2084D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none 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();