License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-block.git] / arch / m32r / mm / init.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
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>
22 #include <linux/pfn.h>
23 #include <linux/gfp.h>
24 #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>
32 #include <asm/sections.h>
33
34 pgd_t swapper_pg_dir[1024];
35
36 /*
37  * Cache of MMU context last used.
38  */
39 #ifndef CONFIG_SMP
40 unsigned long mmu_context_cache_dat;
41 #else
42 unsigned long mmu_context_cache_dat[NR_CPUS];
43 #endif
44
45 /*
46  * function prototype
47  */
48 void __init paging_init(void);
49 void __init mem_init(void);
50 void free_initmem(void);
51 #ifdef CONFIG_BLK_DEV_INITRD
52 void free_initrd_mem(unsigned long, unsigned long);
53 #endif
54
55 /* It'd be good if these lines were in the standard header file. */
56 #define START_PFN(nid)          (NODE_DATA(nid)->bdata->node_min_pfn)
57 #define MAX_LOW_PFN(nid)        (NODE_DATA(nid)->bdata->node_low_pfn)
58
59 #ifndef CONFIG_DISCONTIGMEM
60 void __init zone_sizes_init(void)
61 {
62         unsigned long  zones_size[MAX_NR_ZONES] = {0, };
63         unsigned long  start_pfn;
64
65 #ifdef CONFIG_MMU
66         {
67                 unsigned long  low;
68                 unsigned long  max_dma;
69
70                 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                 }
81         }
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
88         free_area_init_node(0, zones_size, start_pfn, 0);
89 }
90 #else   /* CONFIG_DISCONTIGMEM */
91 extern void zone_sizes_init(void);
92 #endif  /* CONFIG_DISCONTIGMEM */
93
94 /*======================================================================*
95  * paging_init() : sets up the page tables
96  *======================================================================*/
97 void __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 */
109         zone_sizes_init();
110 }
111
112 /*======================================================================*
113  * mem_init() :
114  * orig : arch/sh/mm/init.c
115  *======================================================================*/
116 void __init mem_init(void)
117 {
118 #ifndef CONFIG_MMU
119         extern unsigned long memory_end;
120
121         high_memory = (void *)(memory_end & PAGE_MASK);
122 #else
123         high_memory = (void *)__va(PFN_PHYS(MAX_LOW_PFN(0)));
124 #endif /* CONFIG_MMU */
125
126         /* clear the zero-page */
127         memset(empty_zero_page, 0, PAGE_SIZE);
128
129         set_max_mapnr(get_num_physpages());
130         free_all_bootmem();
131         mem_init_print_info(NULL);
132 }
133
134 /*======================================================================*
135  * free_initmem() :
136  * orig : arch/sh/mm/init.c
137  *======================================================================*/
138 void free_initmem(void)
139 {
140         free_initmem_default(-1);
141 }
142
143 #ifdef CONFIG_BLK_DEV_INITRD
144 /*======================================================================*
145  * free_initrd_mem() :
146  * orig : arch/sh/mm/init.c
147  *======================================================================*/
148 void free_initrd_mem(unsigned long start, unsigned long end)
149 {
150         free_reserved_area((void *)start, (void *)end, -1, "initrd");
151 }
152 #endif