xref: /openbmc/linux/arch/riscv/mm/init.c (revision 65417d9f)
1 /*
2  * Copyright (C) 2012 Regents of the University of California
3  *
4  *   This program is free software; you can redistribute it and/or
5  *   modify it under the terms of the GNU General Public License
6  *   as published by the Free Software Foundation, version 2.
7  *
8  *   This program is distributed in the hope that it will be useful,
9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *   GNU General Public License for more details.
12  */
13 
14 #include <linux/init.h>
15 #include <linux/mm.h>
16 #include <linux/bootmem.h>
17 #include <linux/initrd.h>
18 #include <linux/memblock.h>
19 #include <linux/swap.h>
20 
21 #include <asm/tlbflush.h>
22 #include <asm/sections.h>
23 #include <asm/pgtable.h>
24 #include <asm/io.h>
25 
26 static void __init zone_sizes_init(void)
27 {
28 	unsigned long zones_size[MAX_NR_ZONES];
29 
30 	memset(zones_size, 0, sizeof(zones_size));
31 	zones_size[ZONE_NORMAL] = max_mapnr;
32 	free_area_init_node(0, zones_size, pfn_base, NULL);
33 }
34 
35 void setup_zero_page(void)
36 {
37 	memset((void *)empty_zero_page, 0, PAGE_SIZE);
38 }
39 
40 void __init paging_init(void)
41 {
42 	init_mm.pgd = (pgd_t *)pfn_to_virt(csr_read(sptbr));
43 
44 	setup_zero_page();
45 	local_flush_tlb_all();
46 	zone_sizes_init();
47 }
48 
49 void __init mem_init(void)
50 {
51 #ifdef CONFIG_FLATMEM
52 	BUG_ON(!mem_map);
53 #endif /* CONFIG_FLATMEM */
54 
55 	high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
56 	free_all_bootmem();
57 
58 	mem_init_print_info(NULL);
59 }
60 
61 void free_initmem(void)
62 {
63 	free_initmem_default(0);
64 }
65 
66 #ifdef CONFIG_BLK_DEV_INITRD
67 void free_initrd_mem(unsigned long start, unsigned long end)
68 {
69 }
70 #endif /* CONFIG_BLK_DEV_INITRD */
71