Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3917897imu; Mon, 7 Jan 2019 11:54:47 -0800 (PST) X-Google-Smtp-Source: ALg8bN4NVlHPGK9Q9e0i0czYtagMM0RFh8IDxV2nq9qaB05w5DLS1ED4I7SkPhF/Ca8YRrj75KqP X-Received: by 2002:a63:e80e:: with SMTP id s14mr12058873pgh.30.1546890887776; Mon, 07 Jan 2019 11:54:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546890887; cv=none; d=google.com; s=arc-20160816; b=wK5n0EGlcwphuqkzs3RQ4M8G+/b/aaBZXDhdKDhAyz10i0oqEQPUthkDaWruOzlXsY bB+3KtO1lkJelvt2T9Liq+m1G78heL9/MNPScqfrNbiBCZqG2CNj4F7drp3VJnebGtj5 VD3Bgl5jupIVhJYgLeN7V4JgWCO1ikXDhChmEvsG7ZvB4IDSPZnrFSjW2gSwqMCHHm/A D2h4Eh3ODYfJ+xQ68c1FRPuXsDmXx57nfwOKq9Hk++zvPDPTgcP1AOpwt0pf48ZOkCTz AsxA69DkTBLI5gmZlF8l2u87Jelt4cz4LTl9VoJ3k8y3vgqXuPN6yyIX0iMs7teZ9UFU VS5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=CSYWd6VeFZK8P72VO6QNWHyKLKv+RHglMAIawF/x8uk=; b=Nk2gNafsAx2awP3GjFQBh4RZpIvRc+i2jExSDKWEbxJ1A/LaNsga+hEWCpfnV/Gizn A2p/2UYB/n6tzhjGYIMHFNMNNN+JNcWMuTJ/iOiXsaHqTU90z8Hy1gdvBQsoW0Wn7dFx qaLkTSEJPpGXzpr/4CYRGvG9fHi/v+K7Zfbjp+NRgZATXx5eRQoBw+g9R1Ucn4K5tLah bCdz5IoZWx1PcjLk1vq2iPoXkT1qC2JgL9VKWVu6vOlizF4JpMjVpa8eTjZCqRbzMeHQ zADo1qFcLcjiSjga+JERGrlpSWb/aJJa/vI73a6MoO94t4mKRtou6JUS0WK5qtGIlkAA C+5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=iheGcVmB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j24si7640896pgh.362.2019.01.07.11.54.32; Mon, 07 Jan 2019 11:54:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=iheGcVmB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728960AbfAGQLY (ORCPT + 99 others); Mon, 7 Jan 2019 11:11:24 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34805 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727002AbfAGQLX (ORCPT ); Mon, 7 Jan 2019 11:11:23 -0500 Received: by mail-pg1-f194.google.com with SMTP id j10so348745pga.1 for ; Mon, 07 Jan 2019 08:11:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CSYWd6VeFZK8P72VO6QNWHyKLKv+RHglMAIawF/x8uk=; b=iheGcVmBnGNRZU3bCLq2c45+BKRGm2ge/n6wBqlJo88S5ApAC2vyibvQG/BZ+uKJau 7MZECl+8mdL7EfUkhZbf+l061G3Rez+3xIM6q4a7uudhIiV2gMhB4LvYEkyBlymkxDz+ YFWVJx07s/+MT1XD4yX0rsCwzOl3JWzGlr/v1WKkjCgzHjGesRZng/VUkSikdIJV5t1L r7zJe+AnWwNz7AJwd1KkkkW27OjnbolOm2tK2qj1GnFIZaqT2Ynm9MfvqErrXpKy5OHB gEHzX3r7Jaosj3Fd1BACYFHZtjUVb1QJeIadRAXDWZDY9WOyXSXiOtiwIJgmBN/2ou0i GvGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CSYWd6VeFZK8P72VO6QNWHyKLKv+RHglMAIawF/x8uk=; b=cOO2VrMTIof537g/Il9CPNXi6WA1qQTT4MHjJGDIiBOZzs19JutLBmLU+gj95zj6zf UopcW9dRjzy5wevj0u1Ln/C/y674dXd9X4atI3XG8+GbFKUJwrSDGPW4XvQl3VTV/ety wRFC6p6RYIjGnpIszf9ikA7Z6aBew2DmCLx6CqnFxTO8KthlkP7cXWm4vnske6J+vxu1 4m72cI1msUdPX8mHusx8Y5cBvF8mnNIUMbmc6UX8wjXgJpGLaxBRuUpGv2ghBIYf4zED W1Yj13eZ8hIAfWSTLk0ic8+whOpZQ9NPOl0b1Ewc9biiUGNrLh7K0Y3FnDksZXkDXrD4 +ThA== X-Gm-Message-State: AJcUukd4KaqBncjalRVAhUt4mrZLZEKUB5criErcx391+q6iGrReusG8 +8e4K2+CTKzJeE1J66tk9idXcg== X-Received: by 2002:a63:cc4e:: with SMTP id q14mr11301316pgi.291.1546877482641; Mon, 07 Jan 2019 08:11:22 -0800 (PST) Received: from localhost.localdomain ([49.207.48.214]) by smtp.gmail.com with ESMTPSA id a10sm93243512pfi.138.2019.01.07.08.11.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Jan 2019 08:11:22 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou Cc: Atish Patra , Paul Walmsley , Christoph Hellwig , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH 3/5] RISC-V: Move setup_bootmem() to mm/init.c Date: Mon, 7 Jan 2019 21:40:45 +0530 Message-Id: <20190107161047.10516-4-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190107161047.10516-1-anup@brainfault.org> References: <20190107161047.10516-1-anup@brainfault.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anup Patel The setup_bootmem() mainly populates memblocks and does early memory reservations. The right location for this function is mm/init.c. Signed-off-by: Anup Patel --- arch/riscv/include/asm/pgtable.h | 1 + arch/riscv/kernel/setup.c | 48 ++++---------------------------- arch/riscv/mm/init.c | 40 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 43 deletions(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 16301966d65b..35893810cba3 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -404,6 +404,7 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma, #define kern_addr_valid(addr) (1) /* FIXME */ #endif +extern void setup_bootmem(void); extern void paging_init(void); static inline void pgtable_cache_init(void) diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index f7132547b8b3..49a13b98e13f 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -156,49 +156,6 @@ void __init parse_dtb(unsigned int hartid, void *dtb) early_init_dt_scan(__va(dtb)); } -static void __init setup_bootmem(void) -{ - struct memblock_region *reg; - phys_addr_t mem_size = 0; - - /* Find the memory region containing the kernel */ - for_each_memblock(memory, reg) { - phys_addr_t vmlinux_end = __pa(_end); - phys_addr_t end = reg->base + reg->size; - - if (reg->base <= vmlinux_end && vmlinux_end <= end) { - /* - * Reserve from the start of the region to the end of - * the kernel - */ - memblock_reserve(reg->base, vmlinux_end - reg->base); - mem_size = min(reg->size, (phys_addr_t)-PAGE_OFFSET); - } - } - BUG_ON(mem_size == 0); - - set_max_mapnr(PFN_DOWN(mem_size)); - max_low_pfn = memblock_end_of_DRAM(); - -#ifdef CONFIG_BLK_DEV_INITRD - setup_initrd(); -#endif /* CONFIG_BLK_DEV_INITRD */ - - early_init_fdt_reserve_self(); - early_init_fdt_scan_reserved_mem(); - memblock_allow_resize(); - memblock_dump_all(); - - for_each_memblock(memory, reg) { - unsigned long start_pfn = memblock_region_memory_base_pfn(reg); - unsigned long end_pfn = memblock_region_memory_end_pfn(reg); - - memblock_set_node(PFN_PHYS(start_pfn), - PFN_PHYS(end_pfn - start_pfn), - &memblock.memory, 0); - } -} - void __init setup_arch(char **cmdline_p) { init_mm.start_code = (unsigned long) _stext; @@ -211,6 +168,11 @@ void __init setup_arch(char **cmdline_p) parse_early_param(); setup_bootmem(); + +#ifdef CONFIG_BLK_DEV_INITRD + setup_initrd(); +#endif /* CONFIG_BLK_DEV_INITRD */ + paging_init(); unflatten_device_tree(); diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index f354486f9b78..d0965979ee70 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -62,3 +63,42 @@ void free_initmem(void) { free_initmem_default(0); } + +void __init setup_bootmem(void) +{ + struct memblock_region *reg; + phys_addr_t mem_size = 0; + + /* Find the memory region containing the kernel */ + for_each_memblock(memory, reg) { + phys_addr_t vmlinux_end = __pa(_end); + phys_addr_t end = reg->base + reg->size; + + if (reg->base <= vmlinux_end && vmlinux_end <= end) { + /* + * Reserve from the start of the region to the end of + * the kernel + */ + memblock_reserve(reg->base, vmlinux_end - reg->base); + mem_size = min(reg->size, (phys_addr_t)-PAGE_OFFSET); + } + } + BUG_ON(mem_size == 0); + + set_max_mapnr(PFN_DOWN(mem_size)); + max_low_pfn = memblock_end_of_DRAM(); + + early_init_fdt_reserve_self(); + early_init_fdt_scan_reserved_mem(); + memblock_allow_resize(); + memblock_dump_all(); + + for_each_memblock(memory, reg) { + unsigned long start_pfn = memblock_region_memory_base_pfn(reg); + unsigned long end_pfn = memblock_region_memory_end_pfn(reg); + + memblock_set_node(PFN_PHYS(start_pfn), + PFN_PHYS(end_pfn - start_pfn), + &memblock.memory, 0); + } +} -- 2.17.1