blob: 50fdec54c70a75c6aabd281263139f4dca54a6ef [file] [log] [blame]
Chen Liqin6bc9a392009-06-12 22:01:00 +08001/*
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/gfp.h>
Chen Liqin6bc9a392009-06-12 22:01:00 +080030#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>
Arnd Bergmannfbd85b02009-06-27 15:58:13 +020036#include <linux/initrd.h>
Chen Liqin6bc9a392009-06-12 22:01:00 +080037
Arnd Bergmannfbd85b02009-06-27 15:58:13 +020038#include <asm/sections.h>
Chen Liqin6bc9a392009-06-12 22:01:00 +080039#include <asm/tlb.h>
40
41DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
42
Chen Liqin6bc9a392009-06-12 22:01:00 +080043unsigned long empty_zero_page;
44EXPORT_SYMBOL_GPL(empty_zero_page);
45
46static struct kcore_list kcore_mem, kcore_vmalloc;
47
Arnd Bergmannfbd85b02009-06-27 15:58:13 +020048static unsigned long setup_zero_page(void)
Chen Liqin6bc9a392009-06-12 22:01:00 +080049{
Chen Liqin6bc9a392009-06-12 22:01:00 +080050 struct page *page;
51
Arnd Bergmannfbd85b02009-06-27 15:58:13 +020052 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, 0);
Chen Liqin6bc9a392009-06-12 22:01:00 +080053 if (!empty_zero_page)
54 panic("Oh boy, that early out of memory?");
55
56 page = virt_to_page((void *) empty_zero_page);
Arnd Bergmannfbd85b02009-06-27 15:58:13 +020057 SetPageReserved(page);
Chen Liqin6bc9a392009-06-12 22:01:00 +080058
Arnd Bergmannfbd85b02009-06-27 15:58:13 +020059 return 1UL;
Chen Liqin6bc9a392009-06-12 22:01:00 +080060}
61
62#ifndef CONFIG_NEED_MULTIPLE_NODES
Wu Fengguang61ef2482010-01-22 16:16:19 +080063int page_is_ram(unsigned long pagenr)
Chen Liqin6bc9a392009-06-12 22:01:00 +080064{
65 if (pagenr >= min_low_pfn && pagenr < max_low_pfn)
66 return 1;
67 else
68 return 0;
69}
70
71void __init paging_init(void)
72{
73 unsigned long max_zone_pfns[MAX_NR_ZONES];
74 unsigned long lastpfn;
75
76 pagetable_init();
77 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
78 lastpfn = max_low_pfn;
79 free_area_init_nodes(max_zone_pfns);
80}
81
82void __init mem_init(void)
83{
84 unsigned long codesize, reservedpages, datasize, initsize;
85 unsigned long tmp, ram = 0;
86
Chen Liqin6bc9a392009-06-12 22:01:00 +080087 high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
88 totalram_pages += free_all_bootmem();
Arnd Bergmannfbd85b02009-06-27 15:58:13 +020089 totalram_pages -= setup_zero_page(); /* Setup zeroed pages. */
Chen Liqin6bc9a392009-06-12 22:01:00 +080090 reservedpages = 0;
91
92 for (tmp = 0; tmp < max_low_pfn; tmp++)
93 if (page_is_ram(tmp)) {
94 ram++;
95 if (PageReserved(pfn_to_page(tmp)))
96 reservedpages++;
97 }
98
99 num_physpages = ram;
100 codesize = (unsigned long) &_etext - (unsigned long) &_text;
101 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
102 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
103
Chen Liqin6bc9a392009-06-12 22:01:00 +0800104 printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
105 "%ldk reserved, %ldk data, %ldk init, %ldk highmem)\n",
106 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
107 ram << (PAGE_SHIFT-10), codesize >> 10,
108 reservedpages << (PAGE_SHIFT-10), datasize >> 10,
109 initsize >> 10,
Andreas Fenkart4b529402010-01-08 14:42:31 -0800110 totalhigh_pages << (PAGE_SHIFT-10));
Chen Liqin6bc9a392009-06-12 22:01:00 +0800111}
112#endif /* !CONFIG_NEED_MULTIPLE_NODES */
113
Arnd Bergmannfbd85b02009-06-27 15:58:13 +0200114static void free_init_pages(const char *what, unsigned long begin, unsigned long end)
Chen Liqin6bc9a392009-06-12 22:01:00 +0800115{
116 unsigned long pfn;
117
118 for (pfn = PFN_UP(begin); pfn < PFN_DOWN(end); pfn++) {
119 struct page *page = pfn_to_page(pfn);
120 void *addr = phys_to_virt(PFN_PHYS(pfn));
121
122 ClearPageReserved(page);
123 init_page_count(page);
124 memset(addr, POISON_FREE_INITMEM, PAGE_SIZE);
125 __free_page(page);
126 totalram_pages++;
127 }
128 printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
129}
130
131#ifdef CONFIG_BLK_DEV_INITRD
132void free_initrd_mem(unsigned long start, unsigned long end)
133{
134 free_init_pages("initrd memory",
Arnd Bergmannfbd85b02009-06-27 15:58:13 +0200135 virt_to_phys((void *) start),
136 virt_to_phys((void *) end));
Chen Liqin6bc9a392009-06-12 22:01:00 +0800137}
138#endif
139
140void __init_refok free_initmem(void)
141{
142 free_init_pages("unused kernel memory",
Chen Liqind8aa8992009-08-30 12:26:32 +0800143 __pa(&__init_begin),
144 __pa(&__init_end));
Chen Liqin6bc9a392009-06-12 22:01:00 +0800145}
146
147unsigned long pgd_current;
148
149#define __page_aligned(order) __attribute__((__aligned__(PAGE_SIZE<<order)))
150
151/*
152 * gcc 3.3 and older have trouble determining that PTRS_PER_PGD and PGD_ORDER
153 * are constants. So we use the variants from asm-offset.h until that gcc
154 * will officially be retired.
155 */
Chen Liqind8aa8992009-08-30 12:26:32 +0800156pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned(PTE_ORDER);
Chen Liqin6bc9a392009-06-12 22:01:00 +0800157pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned(PTE_ORDER);