]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - arch/score/mm/init.c
mm/score: use common help functions to free reserved pages
[mirror_ubuntu-focal-kernel.git] / arch / score / mm / init.c
CommitLineData
6bc9a396
CL
1/*
2 * arch/score/mm/init.c
3 *
4 * Score Processor version.
5 *
6 * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
7 * Lennox Wu <lennox.wu@sunplusct.com>
8 * Chen Liqin <liqin.chen@sunplusct.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see the file COPYING, or write
22 * to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#include <linux/errno.h>
27#include <linux/bootmem.h>
28#include <linux/kernel.h>
5a0e3ad6 29#include <linux/gfp.h>
6bc9a396
CL
30#include <linux/init.h>
31#include <linux/mm.h>
32#include <linux/mman.h>
33#include <linux/pagemap.h>
34#include <linux/proc_fs.h>
35#include <linux/sched.h>
fbd85b0e 36#include <linux/initrd.h>
6bc9a396 37
fbd85b0e 38#include <asm/sections.h>
6bc9a396
CL
39#include <asm/tlb.h>
40
6bc9a396
CL
41unsigned long empty_zero_page;
42EXPORT_SYMBOL_GPL(empty_zero_page);
43
44static struct kcore_list kcore_mem, kcore_vmalloc;
45
7265d80f 46static void setup_zero_page(void)
6bc9a396 47{
6bc9a396
CL
48 struct page *page;
49
fbd85b0e 50 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, 0);
6bc9a396
CL
51 if (!empty_zero_page)
52 panic("Oh boy, that early out of memory?");
53
54 page = virt_to_page((void *) empty_zero_page);
7265d80f 55 mark_page_reserved(page);
6bc9a396
CL
56}
57
58#ifndef CONFIG_NEED_MULTIPLE_NODES
61ef2489 59int page_is_ram(unsigned long pagenr)
6bc9a396
CL
60{
61 if (pagenr >= min_low_pfn && pagenr < max_low_pfn)
62 return 1;
63 else
64 return 0;
65}
66
67void __init paging_init(void)
68{
69 unsigned long max_zone_pfns[MAX_NR_ZONES];
70 unsigned long lastpfn;
71
72 pagetable_init();
73 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
74 lastpfn = max_low_pfn;
75 free_area_init_nodes(max_zone_pfns);
76}
77
78void __init mem_init(void)
79{
80 unsigned long codesize, reservedpages, datasize, initsize;
81 unsigned long tmp, ram = 0;
82
6bc9a396
CL
83 high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
84 totalram_pages += free_all_bootmem();
7265d80f 85 setup_zero_page(); /* Setup zeroed pages. */
6bc9a396
CL
86 reservedpages = 0;
87
88 for (tmp = 0; tmp < max_low_pfn; tmp++)
89 if (page_is_ram(tmp)) {
90 ram++;
91 if (PageReserved(pfn_to_page(tmp)))
92 reservedpages++;
93 }
94
95 num_physpages = ram;
96 codesize = (unsigned long) &_etext - (unsigned long) &_text;
97 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
98 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
99
6bc9a396
CL
100 printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
101 "%ldk reserved, %ldk data, %ldk init, %ldk highmem)\n",
102 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
103 ram << (PAGE_SHIFT-10), codesize >> 10,
104 reservedpages << (PAGE_SHIFT-10), datasize >> 10,
105 initsize >> 10,
4b529401 106 totalhigh_pages << (PAGE_SHIFT-10));
6bc9a396
CL
107}
108#endif /* !CONFIG_NEED_MULTIPLE_NODES */
109
6bc9a396
CL
110#ifdef CONFIG_BLK_DEV_INITRD
111void free_initrd_mem(unsigned long start, unsigned long end)
112{
7265d80f 113 free_reserved_area(start, end, POISON_FREE_INITMEM, "initrd");
6bc9a396
CL
114}
115#endif
116
117void __init_refok free_initmem(void)
118{
7265d80f 119 free_initmem_default(POISON_FREE_INITMEM);
6bc9a396
CL
120}
121
122unsigned long pgd_current;
123
124#define __page_aligned(order) __attribute__((__aligned__(PAGE_SIZE<<order)))
125
126/*
127 * gcc 3.3 and older have trouble determining that PTRS_PER_PGD and PGD_ORDER
128 * are constants. So we use the variants from asm-offset.h until that gcc
129 * will officially be retired.
130 */
d8aa899b 131pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned(PTE_ORDER);
6bc9a396 132pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned(PTE_ORDER);