blob: 93abc8c3a46e3cceb7ebed0e7d22f2479a2f904f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/arch/m32r/mm/init.c
4 *
5 * Copyright (c) 2001, 2002 Hitoshi Yamamoto
6 *
7 * Some code taken from sh version.
8 * Copyright (C) 1999 Niibe Yutaka
9 * Based on linux/arch/i386/mm/init.c:
10 * Copyright (C) 1995 Linus Torvalds
11 */
12
13#include <linux/init.h>
14#include <linux/kernel.h>
15#include <linux/mm.h>
16#include <linux/pagemap.h>
17#include <linux/bootmem.h>
18#include <linux/swap.h>
19#include <linux/highmem.h>
20#include <linux/bitops.h>
21#include <linux/nodemask.h>
Dave Hansen22a98352006-03-27 01:16:04 -080022#include <linux/pfn.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/types.h>
25#include <asm/processor.h>
26#include <asm/page.h>
27#include <asm/pgtable.h>
28#include <asm/pgalloc.h>
29#include <asm/mmu_context.h>
30#include <asm/setup.h>
31#include <asm/tlb.h>
Jiang Liu8be65852013-04-29 15:06:40 -070032#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34pgd_t swapper_pg_dir[1024];
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036/*
37 * Cache of MMU context last used.
38 */
39#ifndef CONFIG_SMP
40unsigned long mmu_context_cache_dat;
41#else
42unsigned long mmu_context_cache_dat[NR_CPUS];
43#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45/*
46 * function prototype
47 */
48void __init paging_init(void);
49void __init mem_init(void);
50void free_initmem(void);
51#ifdef CONFIG_BLK_DEV_INITRD
52void free_initrd_mem(unsigned long, unsigned long);
53#endif
54
55/* It'd be good if these lines were in the standard header file. */
Johannes Weiner3560e242008-07-23 21:28:09 -070056#define START_PFN(nid) (NODE_DATA(nid)->bdata->node_min_pfn)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn)
58
59#ifndef CONFIG_DISCONTIGMEM
Jiang Liua0e7b802013-07-03 15:03:59 -070060void __init zone_sizes_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Christoph Lameterf06a9682006-09-25 23:31:10 -070062 unsigned long zones_size[MAX_NR_ZONES] = {0, };
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 unsigned long start_pfn;
64
65#ifdef CONFIG_MMU
Sudip Mukherjee3701dc82016-03-15 14:52:52 -070066 {
67 unsigned long low;
68 unsigned long max_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Sudip Mukherjee3701dc82016-03-15 14:52:52 -070070 start_pfn = START_PFN(0);
71 max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
72 low = MAX_LOW_PFN(0);
73
74 if (low < max_dma) {
75 zones_size[ZONE_DMA] = low - start_pfn;
76 zones_size[ZONE_NORMAL] = 0;
77 } else {
78 zones_size[ZONE_DMA] = low - start_pfn;
79 zones_size[ZONE_NORMAL] = low - max_dma;
80 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 }
82#else
83 zones_size[ZONE_DMA] = 0 >> PAGE_SHIFT;
84 zones_size[ZONE_NORMAL] = __MEMORY_SIZE >> PAGE_SHIFT;
85 start_pfn = __MEMORY_START >> PAGE_SHIFT;
86#endif /* CONFIG_MMU */
87
Johannes Weiner9109fb72008-07-23 21:27:20 -070088 free_area_init_node(0, zones_size, start_pfn, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90#else /* CONFIG_DISCONTIGMEM */
Jiang Liua0e7b802013-07-03 15:03:59 -070091extern void zone_sizes_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#endif /* CONFIG_DISCONTIGMEM */
93
94/*======================================================================*
95 * paging_init() : sets up the page tables
96 *======================================================================*/
97void __init paging_init(void)
98{
99#ifdef CONFIG_MMU
100 int i;
101 pgd_t *pg_dir;
102
103 /* We don't need kernel mapping as hardware support that. */
104 pg_dir = swapper_pg_dir;
105
106 for (i = 0 ; i < USER_PTRS_PER_PGD * 2 ; i++)
107 pgd_val(pg_dir[i]) = 0;
108#endif /* CONFIG_MMU */
Jiang Liua0e7b802013-07-03 15:03:59 -0700109 zone_sizes_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
112/*======================================================================*
113 * mem_init() :
114 * orig : arch/sh/mm/init.c
115 *======================================================================*/
116void __init mem_init(void)
117{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#ifndef CONFIG_MMU
119 extern unsigned long memory_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 high_memory = (void *)(memory_end & PAGE_MASK);
Jiang Liuc5c009f2013-07-03 15:04:26 -0700122#else
123 high_memory = (void *)__va(PFN_PHYS(MAX_LOW_PFN(0)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#endif /* CONFIG_MMU */
125
126 /* clear the zero-page */
127 memset(empty_zero_page, 0, PAGE_SIZE);
128
Jiang Liuc5c009f2013-07-03 15:04:26 -0700129 set_max_mapnr(get_num_physpages());
130 free_all_bootmem();
Jiang Liua0e7b802013-07-03 15:03:59 -0700131 mem_init_print_info(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
134/*======================================================================*
135 * free_initmem() :
136 * orig : arch/sh/mm/init.c
137 *======================================================================*/
138void free_initmem(void)
139{
Jiang Liudbe67df2013-07-03 15:02:51 -0700140 free_initmem_default(-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
143#ifdef CONFIG_BLK_DEV_INITRD
144/*======================================================================*
145 * free_initrd_mem() :
146 * orig : arch/sh/mm/init.c
147 *======================================================================*/
148void free_initrd_mem(unsigned long start, unsigned long end)
149{
Jiang Liudbe67df2013-07-03 15:02:51 -0700150 free_reserved_area((void *)start, (void *)end, -1, "initrd");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152#endif