blob: 11fa717d93b19f2858eec15acce07a9c82617ca7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m32r/mm/init.c
3 *
4 * Copyright (c) 2001, 2002 Hitoshi Yamamoto
5 *
6 * Some code taken from sh version.
7 * Copyright (C) 1999 Niibe Yutaka
8 * Based on linux/arch/i386/mm/init.c:
9 * Copyright (C) 1995 Linus Torvalds
10 */
11
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/mm.h>
15#include <linux/pagemap.h>
16#include <linux/bootmem.h>
17#include <linux/swap.h>
18#include <linux/highmem.h>
19#include <linux/bitops.h>
20#include <linux/nodemask.h>
Dave Hansen22a98352006-03-27 01:16:04 -080021#include <linux/pfn.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/types.h>
24#include <asm/processor.h>
25#include <asm/page.h>
26#include <asm/pgtable.h>
27#include <asm/pgalloc.h>
28#include <asm/mmu_context.h>
29#include <asm/setup.h>
30#include <asm/tlb.h>
Jiang Liu8be65852013-04-29 15:06:40 -070031#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33pgd_t swapper_pg_dir[1024];
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/*
36 * Cache of MMU context last used.
37 */
38#ifndef CONFIG_SMP
39unsigned long mmu_context_cache_dat;
40#else
41unsigned long mmu_context_cache_dat[NR_CPUS];
42#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/*
45 * function prototype
46 */
47void __init paging_init(void);
48void __init mem_init(void);
49void free_initmem(void);
50#ifdef CONFIG_BLK_DEV_INITRD
51void free_initrd_mem(unsigned long, unsigned long);
52#endif
53
54/* It'd be good if these lines were in the standard header file. */
Johannes Weiner3560e242008-07-23 21:28:09 -070055#define START_PFN(nid) (NODE_DATA(nid)->bdata->node_min_pfn)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn)
57
58#ifndef CONFIG_DISCONTIGMEM
Jiang Liua0e7b802013-07-03 15:03:59 -070059void __init zone_sizes_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Christoph Lameterf06a9682006-09-25 23:31:10 -070061 unsigned long zones_size[MAX_NR_ZONES] = {0, };
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 unsigned long start_pfn;
63
64#ifdef CONFIG_MMU
Sudip Mukherjee3701dc82016-03-15 14:52:52 -070065 {
66 unsigned long low;
67 unsigned long max_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Sudip Mukherjee3701dc82016-03-15 14:52:52 -070069 start_pfn = START_PFN(0);
70 max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
71 low = MAX_LOW_PFN(0);
72
73 if (low < max_dma) {
74 zones_size[ZONE_DMA] = low - start_pfn;
75 zones_size[ZONE_NORMAL] = 0;
76 } else {
77 zones_size[ZONE_DMA] = low - start_pfn;
78 zones_size[ZONE_NORMAL] = low - max_dma;
79 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 }
81#else
82 zones_size[ZONE_DMA] = 0 >> PAGE_SHIFT;
83 zones_size[ZONE_NORMAL] = __MEMORY_SIZE >> PAGE_SHIFT;
84 start_pfn = __MEMORY_START >> PAGE_SHIFT;
85#endif /* CONFIG_MMU */
86
Johannes Weiner9109fb72008-07-23 21:27:20 -070087 free_area_init_node(0, zones_size, start_pfn, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89#else /* CONFIG_DISCONTIGMEM */
Jiang Liua0e7b802013-07-03 15:03:59 -070090extern void zone_sizes_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#endif /* CONFIG_DISCONTIGMEM */
92
93/*======================================================================*
94 * paging_init() : sets up the page tables
95 *======================================================================*/
96void __init paging_init(void)
97{
98#ifdef CONFIG_MMU
99 int i;
100 pgd_t *pg_dir;
101
102 /* We don't need kernel mapping as hardware support that. */
103 pg_dir = swapper_pg_dir;
104
105 for (i = 0 ; i < USER_PTRS_PER_PGD * 2 ; i++)
106 pgd_val(pg_dir[i]) = 0;
107#endif /* CONFIG_MMU */
Jiang Liua0e7b802013-07-03 15:03:59 -0700108 zone_sizes_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
111/*======================================================================*
112 * mem_init() :
113 * orig : arch/sh/mm/init.c
114 *======================================================================*/
115void __init mem_init(void)
116{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#ifndef CONFIG_MMU
118 extern unsigned long memory_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 high_memory = (void *)(memory_end & PAGE_MASK);
Jiang Liuc5c009f2013-07-03 15:04:26 -0700121#else
122 high_memory = (void *)__va(PFN_PHYS(MAX_LOW_PFN(0)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#endif /* CONFIG_MMU */
124
125 /* clear the zero-page */
126 memset(empty_zero_page, 0, PAGE_SIZE);
127
Jiang Liuc5c009f2013-07-03 15:04:26 -0700128 set_max_mapnr(get_num_physpages());
129 free_all_bootmem();
Jiang Liua0e7b802013-07-03 15:03:59 -0700130 mem_init_print_info(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
133/*======================================================================*
134 * free_initmem() :
135 * orig : arch/sh/mm/init.c
136 *======================================================================*/
137void free_initmem(void)
138{
Jiang Liudbe67df2013-07-03 15:02:51 -0700139 free_initmem_default(-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
142#ifdef CONFIG_BLK_DEV_INITRD
143/*======================================================================*
144 * free_initrd_mem() :
145 * orig : arch/sh/mm/init.c
146 *======================================================================*/
147void free_initrd_mem(unsigned long start, unsigned long end)
148{
Jiang Liudbe67df2013-07-03 15:02:51 -0700149 free_reserved_area((void *)start, (void *)end, -1, "initrd");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151#endif