blob: 9fbce49ad3bdd4304226aa767c8f5b2fcd2e0a49 [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>
David Howells2f96b8c2013-04-12 00:10:25 +010034#include <linux/kcore.h>
Chen Liqin6bc9a392009-06-12 22:01:00 +080035#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
Chen Liqin6bc9a392009-06-12 22:01:00 +080041unsigned long empty_zero_page;
42EXPORT_SYMBOL_GPL(empty_zero_page);
43
Jiang Liu7265d802013-04-29 15:06:49 -070044static void setup_zero_page(void)
Chen Liqin6bc9a392009-06-12 22:01:00 +080045{
Chen Liqin6bc9a392009-06-12 22:01:00 +080046 struct page *page;
47
Arnd Bergmannfbd85b02009-06-27 15:58:13 +020048 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, 0);
Chen Liqin6bc9a392009-06-12 22:01:00 +080049 if (!empty_zero_page)
50 panic("Oh boy, that early out of memory?");
51
52 page = virt_to_page((void *) empty_zero_page);
Jiang Liu7265d802013-04-29 15:06:49 -070053 mark_page_reserved(page);
Chen Liqin6bc9a392009-06-12 22:01:00 +080054}
55
56#ifndef CONFIG_NEED_MULTIPLE_NODES
Wu Fengguang61ef2482010-01-22 16:16:19 +080057int page_is_ram(unsigned long pagenr)
Chen Liqin6bc9a392009-06-12 22:01:00 +080058{
59 if (pagenr >= min_low_pfn && pagenr < max_low_pfn)
60 return 1;
61 else
62 return 0;
63}
64
65void __init paging_init(void)
66{
67 unsigned long max_zone_pfns[MAX_NR_ZONES];
68 unsigned long lastpfn;
69
70 pagetable_init();
71 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
72 lastpfn = max_low_pfn;
73 free_area_init_nodes(max_zone_pfns);
74}
75
76void __init mem_init(void)
77{
Chen Liqin6bc9a392009-06-12 22:01:00 +080078 high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
Jiang Liu0c988532013-07-03 15:03:24 -070079 free_all_bootmem();
Jiang Liu7265d802013-04-29 15:06:49 -070080 setup_zero_page(); /* Setup zeroed pages. */
Chen Liqin6bc9a392009-06-12 22:01:00 +080081
Jiang Liuad941982013-07-03 15:04:11 -070082 mem_init_print_info(NULL);
Chen Liqin6bc9a392009-06-12 22:01:00 +080083}
84#endif /* !CONFIG_NEED_MULTIPLE_NODES */
85
Chen Liqin6bc9a392009-06-12 22:01:00 +080086#ifdef CONFIG_BLK_DEV_INITRD
87void free_initrd_mem(unsigned long start, unsigned long end)
88{
Jiang Liu11199692013-07-03 15:02:48 -070089 free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
90 "initrd");
Chen Liqin6bc9a392009-06-12 22:01:00 +080091}
92#endif
93
94void __init_refok free_initmem(void)
95{
Jiang Liu7265d802013-04-29 15:06:49 -070096 free_initmem_default(POISON_FREE_INITMEM);
Chen Liqin6bc9a392009-06-12 22:01:00 +080097}
98
99unsigned long pgd_current;
100
101#define __page_aligned(order) __attribute__((__aligned__(PAGE_SIZE<<order)))
102
103/*
104 * gcc 3.3 and older have trouble determining that PTRS_PER_PGD and PGD_ORDER
105 * are constants. So we use the variants from asm-offset.h until that gcc
106 * will officially be retired.
107 */
Chen Liqind8aa8992009-08-30 12:26:32 +0800108pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned(PTE_ORDER);
Chen Liqin6bc9a392009-06-12 22:01:00 +0800109pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned(PTE_ORDER);