Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3860416imj; Tue, 12 Feb 2019 06:01:40 -0800 (PST) X-Google-Smtp-Source: AHgI3IZVUf+hRmH+8vlreux1gb+uS87G1sTBmU4nBLIWTEjtUJcjxfF0keHnpDMQSEBiYz+bjIPC X-Received: by 2002:a17:902:b402:: with SMTP id x2mr4159760plr.53.1549980099978; Tue, 12 Feb 2019 06:01:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549980099; cv=none; d=google.com; s=arc-20160816; b=SuektritpoHjuH7UrY94PtFvbq3qqjg1UIsC7M8FOFWFiExurz3/lgv+KbccoqIdj0 OxYwEOAPkqv3EoIOJJ37d2ZlawDZjuSGPga+T22aIOhUu8hcX6oNkmkDDbjVxqVRlHio S3nrzbkwuF+T4tld3cSjMH4DPKBgrbGts4nd2Ir3GEpBnpxFw9/x3nJ6HsimR4y7YhvK LfJmbbuvSJKM8TXpnrrhqMQH/0YVKyD8qBsFNzCU3KPvf4AqUoprv3T5Qznt6jaqDTRf G2RqWxcYQgmFH8KXXiuOMZ/oNEWhCb4I08SnF4sqxh4c/6fjeZi9Ni2geW7WnyT4faL3 eElA== 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=lL6B39zTRMesFFycvJsi7f9wzh2NABawCwlr1Qo+OTc=; b=udtHACrY1brjb8un+YM2hu9xjiN48rG11U1uW5Gr9iOYQZ0+E+eR+hw3asJEXQNdEr B/V+J9luwiYQx3B3//MOFvlc53MMdCzY2p9WDfAoV3XPPoeMu9nejIN3KohizRinUSLz 07vCBx4BpqmNPsnn00RaRjb0malkU/dZQL8akBQ9iFsQ1GDBXWwLjuDOEpJMIttzUiFw ARlm3cyQLNUjEktbDETppRNckF7ACFEJxfO1v8qYIX/v8L3t/tjUGB2zIL1IdIsIGohn 3ljHXU2HjPYuu5phCPwLr6PPi6n1JMJKhUcSjhNINvEcSAtXUjF4XhKSYC8UAarWlmt1 mnxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=FHa+wip3; dkim=pass header.i=@sharedspace.onmicrosoft.com header.s=selector1-wdc-com header.b=nzz5qKs8; 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 l81si6770445pfj.230.2019.02.12.06.01.21; Tue, 12 Feb 2019 06:01:39 -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=FHa+wip3; dkim=pass header.i=@sharedspace.onmicrosoft.com header.s=selector1-wdc-com header.b=nzz5qKs8; 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 S1730109AbfBLOAa (ORCPT + 99 others); Tue, 12 Feb 2019 09:00:30 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:62965 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730097AbfBLOA3 (ORCPT ); Tue, 12 Feb 2019 09:00:29 -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=1549980029; x=1581516029; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=MMaSjPVSOs1KuGPAIVXOULMT9o2j1tPbTgBb8+q2ItQ=; b=FHa+wip3Kg8ltSLGw1UepHvqxj87w9AGpShbaNeJAGlDtzcBre7dWP7h 7LBN1PX2f9qwnvy6sZijdSmvZAnzwYf9CgVIMeS5CjkgBzDYyVlmdkdoj lgD7ejDVYYcTs9BVMmf00TslrXPhAJ/BwOtCFBSFR7EEoiWUrl7XlK9zt XbdT/Npgt9nCQ9MdtwoZTmiOPPI3g0T2t0efVbGI2v4Nb+K7gr8nhPxLG RZqrKfljrqtBbXCczHbEodIAy7bAxEzPoJbbYqE4ZHcPBFS4jsBEEaoE2 t80jSQvr+1BR1VCL6Fm8GFYva0dbHX3QWtvIVaqCLv3WlOBDZu2HK1jjC Q==; X-IronPort-AV: E=Sophos;i="5.58,362,1544457600"; d="scan'208";a="101010259" Received: from mail-bn3nam04lp2055.outbound.protection.outlook.com (HELO NAM04-BN3-obe.outbound.protection.outlook.com) ([104.47.46.55]) by ob1.hgst.iphmx.com with ESMTP; 12 Feb 2019 22:00:28 +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=lL6B39zTRMesFFycvJsi7f9wzh2NABawCwlr1Qo+OTc=; b=nzz5qKs8CZYupXh34LRzcvbUuUlJ+lUMKWHPKRYwAFx9HDMCc/61tBCM66jlsUALnfVo+anRlu8W/VdxoGB+e7cFXtOucZfw8+7fL+RCN5dX6U72DMPgB76l4WnVMAFga6I4cR24WTtA/ng3fUdoNgwmduiiV0NYxDSJ3xlneZc= Received: from MN2PR04MB6061.namprd04.prod.outlook.com (20.178.247.148) by MN2PR04MB6224.namprd04.prod.outlook.com (20.178.247.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1601.22; Tue, 12 Feb 2019 14:00:26 +0000 Received: from MN2PR04MB6061.namprd04.prod.outlook.com ([fe80::2cdb:c465:af57:8be1]) by MN2PR04MB6061.namprd04.prod.outlook.com ([fe80::2cdb:c465:af57:8be1%7]) with mapi id 15.20.1601.023; Tue, 12 Feb 2019 14:00:26 +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 v3 3/6] RISC-V: Move setup_bootmem() to mm/init.c Thread-Topic: [PATCH v3 3/6] RISC-V: Move setup_bootmem() to mm/init.c Thread-Index: AQHUwttOdTsDzGHhY0ijRWgwbLe67g== Date: Tue, 12 Feb 2019 14:00:26 +0000 Message-ID: <20190212135942.105008-4-anup.patel@wdc.com> References: <20190212135942.105008-1-anup.patel@wdc.com> In-Reply-To: <20190212135942.105008-1-anup.patel@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MA1PR01CA0126.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:35::20) To MN2PR04MB6061.namprd04.prod.outlook.com (2603:10b6:208:de::20) 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: [49.207.48.205] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b065dd46-7425-4aec-8e56-08d690f2705a x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600110)(711020)(4605077)(4618075)(2017052603328)(7153060)(7193020);SRVR:MN2PR04MB6224; x-ms-traffictypediagnostic: MN2PR04MB6224: wdcipoutbound: EOP-TRUE x-microsoft-exch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6zJvAA/vB4/GmRaq6iUDdXzXkdXBLicwghXeL90?= =?iso-8859-1?Q?z6x6bUqaBhPDTYUt7srgy80wLUNdFM/d8+/wz4+lHP8iAGDXNedL41r2og?= =?iso-8859-1?Q?4VLQaFp4D4CWu9SagNSF9QLFfXZsDVi62Epa35YEc+wOtlNHy6FwDUg4lW?= =?iso-8859-1?Q?KRx0kSgq28iJ1faKbQuSrHFiuKds7rJW+RYSCif5U0CCYLFbgtvC+Qq/V+?= =?iso-8859-1?Q?kXfiSdhTVFCwPGfZZySonuezhCTJsKi5e9V3jr7uUhgikpuecMcGcpFQxx?= =?iso-8859-1?Q?+3TFlbgXwEd6E9gvjAjBOWAcivjPYQSBcWMCZPzDMOyCj2e7zQO6a5Huha?= =?iso-8859-1?Q?bRp16+kQuR0ijuvWyhK3wMp6gmyQ1wdZRRiMK1h674JoWOHwntiNzq6EWn?= =?iso-8859-1?Q?m/BMH7TIB7NQUAi9VMTmKE4oAIkOWHeJJPDliNLc0lmbYLVpcCc0r5lNMy?= =?iso-8859-1?Q?tYImwY/WjKLyatL3v0S2QFP?= x-microsoft-antispam-prvs: x-forefront-prvs: 0946DC87A1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(396003)(39860400002)(346002)(376002)(136003)(199004)(189003)(11346002)(25786009)(2616005)(72206003)(486006)(2171002)(478600001)(4326008)(446003)(14454004)(6512007)(476003)(52116002)(36756003)(110136005)(97736004)(3846002)(6116002)(8936002)(50226002)(76176011)(54906003)(99286004)(7736002)(256004)(106356001)(316002)(81166006)(105586002)(68736007)(186003)(8676002)(44832011)(1076003)(6486002)(6436002)(86362001)(66066001)(53936002)(2906002)(305945005)(55236004)(386003)(71200400001)(102836004)(6506007)(71190400001)(26005)(81156014);DIR:OUT;SFP:1102;SCL:1;SRVR:MN2PR04MB6224;H:MN2PR04MB6061.namprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: +My5kfXJ+yNGSpeXFSzUxdzTdZeyWV8hts1Da/a016BF4D4+7Vb3LclqSdmbm5MIWlXo+EnbCj7S5bp4icPeah7mpkp2paZ/WuTZAnFg2jGhUQZXEaG9H++38TN2+QJmKM5ktGNFjKQEyWnLoJKu/+R9uempVHnSb/KnkdS0bsvFZSU7Upm12INAkNubJkPPQi5ij4JtjIESYxoU0gvizdReIZ1ccQTAQ8wZ/24yLknQ439nVzGacOmo3IppRNJirnVpkeEgBVOqLbA17l/mLsIwiYXbkP7sFCm3nf4yXYsjro4zVdZRAWXMw+UTnJHmACTXYs5qN+e/nFSkwUucB02dYR53RCdvg+Yt0HFVNfzjGxTBnF7thORaoIeZHusz8Wqem3/aajkx/zu8JfsCkaX3HixXf9wAodnZEyftl5c= 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: b065dd46-7425-4aec-8e56-08d690f2705a X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Feb 2019 14:00:23.6544 (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: MN2PR04MB6224 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 --- 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