Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4827776imj; Wed, 13 Feb 2019 01:38:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IYE4GPMNzQMmR3Q8auEN51y8TKwSsrigjYsuwHpWXPVmA0gPYU6d5qcoCHEikjxZzpKnBFN X-Received: by 2002:a17:902:e287:: with SMTP id cf7mr9046129plb.51.1550050684915; Wed, 13 Feb 2019 01:38:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550050684; cv=none; d=google.com; s=arc-20160816; b=eqrRm8DYKa03YGezTfcroM3xkSgs9Gnl7ip9bJtY+NLOQctCwx5eHSqnD+d2so/Mry CAjjcABFr4bDPmb2EJYMpWrEzUWke0apFdKDFwh6m2skaao404GHsPv/VtUy0DNT1k/P ZWcnlGwP5ID5hJWzewmB45PV7EQXJtTSNWeje/1KwoEsY63MkCiMGKh66OEFTRsQIJ6o J+lE4j61FWoZMtIqHsNsqJ90MoOG3craRigFfTe8VQLd3ogLvgPztX2E57E+GjF830DE 3gmyeXVvB8nYEyxcunFvUfyXgCPI37zQyiJdwk8CmuQZDs2pzC31EQ7OKovo/0vgUsOb WmSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :wdcipoutbound:content-language:accept-language:in-reply-to :references:message-id:date:thread-index:thread-topic:subject:cc:to :from:dkim-signature:dkim-signature; bh=nZYC+n40qSzR4f+zCg6G37FQlaEhcuFjDfi10z8r5e4=; b=mAEsgnXHEZX0ZjZn9qRI+llHX4I/pVnCHMVmhNxaBig28qYFdPeJAvl5iERN3oO5jX rUEjkURobzxXJcZgNfGpJAPlRN/XaIlgff0XXawjhUKMn22U52O4G9M0P3Np3PFkHAIQ jlHsH1DXmTiPpT1dECrWxqjpWOly+CSPiOHlUh+drVeZMBJQi9qW2etIZN/N70VNDCyo FLk+Iz4sMaK54NINxGdT0Re0xfhMRHDn6wczPi4xrw2tvGXWCWMvuP/lj2kSA5ALSwaH YrsLAeEFXbhtzcSGRPff86GLeHtROwTQiz0yDPjYHD5ILfhA/7T8iN4Bg3/tNBt/h4x1 LM9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=fFp2AW9q; dkim=pass header.i=@sharedspace.onmicrosoft.com header.s=selector1-wdc-com header.b=mRyBbgeC; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si7643750pgp.546.2019.02.13.01.37.48; Wed, 13 Feb 2019 01:38:04 -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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=fFp2AW9q; dkim=pass header.i=@sharedspace.onmicrosoft.com header.s=selector1-wdc-com header.b=mRyBbgeC; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733055AbfBMGcO (ORCPT + 99 others); Wed, 13 Feb 2019 01:32:14 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:14865 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728793AbfBMGcN (ORCPT ); Wed, 13 Feb 2019 01:32:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1550039534; x=1581575534; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=PuUS9APfMCm0201mEnejJ6ms7yQO4HAQocfr3TMtdYE=; b=fFp2AW9qPTXWZAm0JSE/8s+1ShlhpjpD5iLjs4hB4IKNtPc8ktwr+Ws3 FUajjyP7CQPdHnLMHnuusDag2TY0rZOBVzPsrWiq5FfeDNKS34P5C7Avo Io1263qvhR3QJUHx4PPziPBljORZCdM8lAXKAeV0EyUjYzj/Vf/E0jiGS a+NTkYc7w5EI2BPQiR4uDg5/gHzGIhksvsU4376lBGUhFXaQF8CGYFiUU 58NjwuwWuuCoEoX0+Ks29IHhlfCbZ6uvRj1wdmfQMFQxJbkg4oKZOriiR tNTYgoHVyqmJWeAamt+dNypfApyzp7eeZD4/Yb9MLk8lkBWdiDC9cyQPA A==; X-IronPort-AV: E=Sophos;i="5.58,364,1544457600"; d="scan'208";a="102393223" Received: from mail-by2nam03lp2052.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) ([104.47.42.52]) by ob1.hgst.iphmx.com with ESMTP; 13 Feb 2019 14:32:13 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nZYC+n40qSzR4f+zCg6G37FQlaEhcuFjDfi10z8r5e4=; b=mRyBbgeClFKZMaAfzmgezpm9ltAuAB1EZN16QH+JS6EY7rZ30LESBy2naTn5k8+AwApz4XxId3hIR2S/bC3toBSMVFFAS7+vK1lPvvsCx+XhZrJIYmlwm7GyYldC4S393ebazOx6maR//F6E7CpgqhhIfxnTsLWlTRJKsJV9nzM= Received: from DM6PR04MB6059.namprd04.prod.outlook.com (20.178.226.89) by DM6PR04MB4699.namprd04.prod.outlook.com (20.176.107.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1622.16; Wed, 13 Feb 2019 06:32:11 +0000 Received: from DM6PR04MB6059.namprd04.prod.outlook.com ([fe80::d006:5be7:c3f:ba6c]) by DM6PR04MB6059.namprd04.prod.outlook.com ([fe80::d006:5be7:c3f:ba6c%2]) with mapi id 15.20.1601.023; Wed, 13 Feb 2019 06:32:11 +0000 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 v4 3/6] RISC-V: Move setup_bootmem() to mm/init.c Thread-Topic: [PATCH v4 3/6] RISC-V: Move setup_bootmem() to mm/init.c Thread-Index: AQHUw2XZrm8QKiLFmkqv8lvDo8ck6w== Date: Wed, 13 Feb 2019 06:32:11 +0000 Message-ID: <20190213063127.28703-4-anup.patel@wdc.com> References: <20190213063127.28703-1-anup.patel@wdc.com> In-Reply-To: <20190213063127.28703-1-anup.patel@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MA1PR0101CA0027.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::13) To DM6PR04MB6059.namprd04.prod.outlook.com (2603:10b6:5:129::25) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Anup.Patel@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [129.253.179.161] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4e0fa01b-180d-4672-d2c6-08d6917cfc27 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600110)(711020)(4605077)(4618075)(2017052603328)(7153060)(7193020);SRVR:DM6PR04MB4699; x-ms-traffictypediagnostic: DM6PR04MB4699: wdcipoutbound: EOP-TRUE x-microsoft-exchange-diagnostics: =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Z4gFkfEgWHkHLKckB1Hs5YEtI?= =?iso-8859-1?Q?RRZAVYentBQMkxor80rEZLfAxXyDDHrtuPFsCS/KthJkaeeuE233NiMnTH?= =?iso-8859-1?Q?Vb6uZHqPGJxMkf9xkSjM/N8NC9nU0W/P3yhu7tIMDRg9bcDwxcezpVj9eO?= =?iso-8859-1?Q?iZcpe8S1vA1ujeRMFYbh77B/IWcnGeIlL4lF/DkYJcAqh6cB/gqZ0mi/1Q?= =?iso-8859-1?Q?4Jv9/F2rQYUqDbw7WE1jn5FfxJLBo6/iJxYAZcyqRi2oHznUwU0S45ZZC0?= =?iso-8859-1?Q?cyzKZht9BMNH8KNINuKJLuuot3xpNfNJATBnVA5ALb6F3g/U+oN0SOHH8s?= =?iso-8859-1?Q?5aDn4IM34XH3C9PTdKVrJliBFUkXTsPTMlOfgEVJAmdcNiv8fa53a1v5R3?= =?iso-8859-1?Q?7Wejmew/Xr0764nTz/cxqPfd8s6J0gmWBPMcmSIkGfUlwzySrAc2189NkD?= =?iso-8859-1?Q?vI=3D?= x-microsoft-antispam-prvs: x-forefront-prvs: 094700CA91 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(366004)(346002)(396003)(136003)(39860400002)(189003)(199004)(72206003)(446003)(106356001)(478600001)(6486002)(36756003)(6512007)(25786009)(11346002)(476003)(99286004)(6116002)(2616005)(4326008)(66066001)(102836004)(3846002)(486006)(386003)(76176011)(6436002)(6506007)(52116002)(105586002)(14454004)(2906002)(8676002)(26005)(1076003)(53936002)(71190400001)(256004)(50226002)(97736004)(68736007)(316002)(81166006)(81156014)(110136005)(8936002)(86362001)(54906003)(44832011)(2171002)(186003)(7736002)(71200400001)(305945005);DIR:OUT;SFP:1102;SCL:1;SRVR:DM6PR04MB4699;H:DM6PR04MB6059.namprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: R3mIPPmE+eo+KUaSqH7gpYmpN+cu/fDV2oRg/cuJqNmRwg/YZWjO67Et/eQgCG51beNw3W5LfHYKndYutZtqyRfCs9g6oxJVfgPdScldNGJfpAe/bNp6WAeHqviK859Py7VIaWAWluBA8Ej9ihQpnwAx1phRnEn9y78oMYuwCAtLyUY4P2QSrOhuhDuHPPvKj66O6kza/599DzWlBLLYhBcLlVEYJf0Hnr3Gdd2ffNgciJMS6pIhpgyV2GFUobsbOGkyVELb7lpcf1FlUPGdLpCszCeo/uEUDWpKghxy1MnfWcGpMx5AxjqGtedxTrR/eofhRdewMZLhfLKPO9vemxF0ZIWNYs3lina8obi7zu1S1DkJ9yTmQRfabbyTrASAIo/jqfGMoJGTGzoJkL8qbAmq24dWsJ5xm+G4rRn+VlU= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e0fa01b-180d-4672-d2c6-08d6917cfc27 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Feb 2019 06:32:08.4234 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB4699 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Christoph Hellwig Reviewed-by: Palmer Dabbelt --- 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/pgta= ble.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 =20 +extern void setup_bootmem(void); extern void paging_init(void); =20 static inline void pgtable_cache_init(void) diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 9e6395b7d409..ab29a66a17fc 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -163,49 +163,6 @@ void __init parse_dtb(unsigned int hartid, void *dtb) #endif } =20 -static void __init setup_bootmem(void) -{ - struct memblock_region *reg; - phys_addr_t mem_size =3D 0; - - /* Find the memory region containing the kernel */ - for_each_memblock(memory, reg) { - phys_addr_t vmlinux_end =3D __pa(_end); - phys_addr_t end =3D reg->base + reg->size; - - if (reg->base <=3D vmlinux_end && vmlinux_end <=3D end) { - /* - * Reserve from the start of the region to the end of - * the kernel - */ - memblock_reserve(reg->base, vmlinux_end - reg->base); - mem_size =3D min(reg->size, (phys_addr_t)-PAGE_OFFSET); - } - } - BUG_ON(mem_size =3D=3D 0); - - set_max_mapnr(PFN_DOWN(mem_size)); - max_low_pfn =3D PFN_DOWN(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 =3D memblock_region_memory_base_pfn(reg); - unsigned long end_pfn =3D 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 =3D (unsigned long) _stext; @@ -218,6 +175,11 @@ void __init setup_arch(char **cmdline_p) parse_early_param(); =20 setup_bootmem(); + +#ifdef CONFIG_BLK_DEV_INITRD + setup_initrd(); +#endif /* CONFIG_BLK_DEV_INITRD */ + paging_init(); unflatten_device_tree(); =20 diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 504a5e491f5a..a57dba8ac9e7 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -16,6 +16,7 @@ #include #include #include +#include =20 #include #include @@ -63,3 +64,42 @@ void free_initmem(void) { free_initmem_default(0); } + +void __init setup_bootmem(void) +{ + struct memblock_region *reg; + phys_addr_t mem_size =3D 0; + + /* Find the memory region containing the kernel */ + for_each_memblock(memory, reg) { + phys_addr_t vmlinux_end =3D __pa(_end); + phys_addr_t end =3D reg->base + reg->size; + + if (reg->base <=3D vmlinux_end && vmlinux_end <=3D end) { + /* + * Reserve from the start of the region to the end of + * the kernel + */ + memblock_reserve(reg->base, vmlinux_end - reg->base); + mem_size =3D min(reg->size, (phys_addr_t)-PAGE_OFFSET); + } + } + BUG_ON(mem_size =3D=3D 0); + + set_max_mapnr(PFN_DOWN(mem_size)); + max_low_pfn =3D 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 =3D memblock_region_memory_base_pfn(reg); + unsigned long end_pfn =3D memblock_region_memory_end_pfn(reg); + + memblock_set_node(PFN_PHYS(start_pfn), + PFN_PHYS(end_pfn - start_pfn), + &memblock.memory, 0); + } +} --=20 2.17.1