Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | /* |
3 | * linux/arch/m32r/kernel/setup.c | |
4 | * | |
5 | * Setup routines for Renesas M32R | |
6 | * | |
7 | * Copyright (c) 2001, 2002 Hiroyuki Kondo, Hirokazu Takata, | |
8 | * Hitoshi Yamamoto | |
9 | */ | |
10 | ||
1da177e4 | 11 | #include <linux/init.h> |
7c1c4e54 | 12 | #include <linux/kernel.h> |
1da177e4 LT |
13 | #include <linux/stddef.h> |
14 | #include <linux/fs.h> | |
68e21be2 | 15 | #include <linux/sched/mm.h> |
1da177e4 LT |
16 | #include <linux/ioport.h> |
17 | #include <linux/mm.h> | |
18 | #include <linux/bootmem.h> | |
19 | #include <linux/console.h> | |
20 | #include <linux/initrd.h> | |
21 | #include <linux/major.h> | |
22 | #include <linux/root_dev.h> | |
23 | #include <linux/seq_file.h> | |
24 | #include <linux/timex.h> | |
894673ee | 25 | #include <linux/screen_info.h> |
1da177e4 LT |
26 | #include <linux/cpu.h> |
27 | #include <linux/nodemask.h> | |
22a9835c | 28 | #include <linux/pfn.h> |
1da177e4 LT |
29 | |
30 | #include <asm/processor.h> | |
31 | #include <asm/pgtable.h> | |
32 | #include <asm/io.h> | |
33 | #include <asm/mmu_context.h> | |
34 | #include <asm/m32r.h> | |
35 | #include <asm/setup.h> | |
36 | #include <asm/sections.h> | |
37 | ||
38 | #ifdef CONFIG_MMU | |
39 | extern void init_mmu(void); | |
40 | #endif | |
41 | ||
1da177e4 LT |
42 | extern char _end[]; |
43 | ||
44 | /* | |
45 | * Machine setup.. | |
46 | */ | |
47 | struct cpuinfo_m32r boot_cpu_data; | |
48 | ||
49 | #ifdef CONFIG_BLK_DEV_RAM | |
50 | extern int rd_doload; /* 1 = load ramdisk, 0 = don't load */ | |
51 | extern int rd_prompt; /* 1 = prompt for ramdisk, 0 = don't prompt */ | |
52 | extern int rd_image_start; /* starting block # of image */ | |
53 | #endif | |
54 | ||
55 | #if defined(CONFIG_VGA_CONSOLE) | |
56 | struct screen_info screen_info = { | |
57 | .orig_video_lines = 25, | |
58 | .orig_video_cols = 80, | |
59 | .orig_video_mode = 0, | |
60 | .orig_video_ega_bx = 0, | |
61 | .orig_video_isVGA = 1, | |
62 | .orig_video_points = 8 | |
63 | }; | |
64 | #endif | |
65 | ||
66 | extern int root_mountflags; | |
67 | ||
3561794d | 68 | static char __initdata command_line[COMMAND_LINE_SIZE]; |
1da177e4 LT |
69 | |
70 | static struct resource data_resource = { | |
71 | .name = "Kernel data", | |
72 | .start = 0, | |
73 | .end = 0, | |
35d98e93 | 74 | .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM |
1da177e4 LT |
75 | }; |
76 | ||
77 | static struct resource code_resource = { | |
78 | .name = "Kernel code", | |
79 | .start = 0, | |
80 | .end = 0, | |
35d98e93 | 81 | .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM |
1da177e4 LT |
82 | }; |
83 | ||
84 | unsigned long memory_start; | |
601f1db6 SM |
85 | EXPORT_SYMBOL(memory_start); |
86 | ||
1da177e4 | 87 | unsigned long memory_end; |
601f1db6 | 88 | EXPORT_SYMBOL(memory_end); |
1da177e4 LT |
89 | |
90 | void __init setup_arch(char **); | |
91 | int get_cpuinfo(char *); | |
92 | ||
93 | static __inline__ void parse_mem_cmdline(char ** cmdline_p) | |
94 | { | |
95 | char c = ' '; | |
96 | char *to = command_line; | |
97 | char *from = COMMAND_LINE; | |
98 | int len = 0; | |
99 | int usermem = 0; | |
100 | ||
101 | /* Save unparsed command line copy for /proc/cmdline */ | |
3561794d ABL |
102 | memcpy(boot_command_line, COMMAND_LINE, COMMAND_LINE_SIZE); |
103 | boot_command_line[COMMAND_LINE_SIZE-1] = '\0'; | |
1da177e4 LT |
104 | |
105 | memory_start = (unsigned long)CONFIG_MEMORY_START+PAGE_OFFSET; | |
106 | memory_end = memory_start+(unsigned long)CONFIG_MEMORY_SIZE; | |
107 | ||
108 | for ( ; ; ) { | |
109 | if (c == ' ' && !memcmp(from, "mem=", 4)) { | |
110 | if (to != command_line) | |
111 | to--; | |
112 | ||
113 | { | |
114 | unsigned long mem_size; | |
115 | ||
116 | usermem = 1; | |
117 | mem_size = memparse(from+4, &from); | |
118 | memory_end = memory_start + mem_size; | |
119 | } | |
120 | } | |
121 | c = *(from++); | |
122 | if (!c) | |
123 | break; | |
124 | ||
125 | if (COMMAND_LINE_SIZE <= ++len) | |
126 | break; | |
127 | ||
128 | *(to++) = c; | |
129 | } | |
130 | *to = '\0'; | |
131 | *cmdline_p = command_line; | |
132 | if (usermem) | |
133 | printk(KERN_INFO "user-defined physical RAM map:\n"); | |
134 | } | |
135 | ||
136 | #ifndef CONFIG_DISCONTIGMEM | |
137 | static unsigned long __init setup_memory(void) | |
138 | { | |
139 | unsigned long start_pfn, max_low_pfn, bootmap_size; | |
140 | ||
141 | start_pfn = PFN_UP( __pa(_end) ); | |
142 | max_low_pfn = PFN_DOWN( __pa(memory_end) ); | |
143 | ||
144 | /* | |
145 | * Initialize the boot-time allocator (with low memory only): | |
146 | */ | |
147 | bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn, | |
148 | CONFIG_MEMORY_START>>PAGE_SHIFT, max_low_pfn); | |
149 | ||
150 | /* | |
151 | * Register fully available low RAM pages with the bootmem allocator. | |
152 | */ | |
153 | { | |
154 | unsigned long curr_pfn; | |
155 | unsigned long last_pfn; | |
156 | unsigned long pages; | |
157 | ||
158 | /* | |
159 | * We are rounding up the start address of usable memory: | |
160 | */ | |
161 | curr_pfn = PFN_UP(__pa(memory_start)); | |
162 | ||
163 | /* | |
164 | * ... and at the end of the usable range downwards: | |
165 | */ | |
166 | last_pfn = PFN_DOWN(__pa(memory_end)); | |
167 | ||
168 | if (last_pfn > max_low_pfn) | |
169 | last_pfn = max_low_pfn; | |
170 | ||
171 | pages = last_pfn - curr_pfn; | |
172 | free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(pages)); | |
173 | } | |
174 | ||
175 | /* | |
176 | * Reserve the kernel text and | |
177 | * Reserve the bootmem bitmap. We do this in two steps (first step | |
178 | * was init_bootmem()), because this catches the (definitely buggy) | |
179 | * case of us accidentally initializing the bootmem allocator with | |
180 | * an invalid RAM area. | |
181 | */ | |
182 | reserve_bootmem(CONFIG_MEMORY_START + PAGE_SIZE, | |
183 | (PFN_PHYS(start_pfn) + bootmap_size + PAGE_SIZE - 1) | |
72a7fe39 BW |
184 | - CONFIG_MEMORY_START, |
185 | BOOTMEM_DEFAULT); | |
1da177e4 LT |
186 | |
187 | /* | |
188 | * reserve physical page 0 - it's a special BIOS page on many boxes, | |
189 | * enabling clean reboots, SMP operation, laptop functions. | |
190 | */ | |
72a7fe39 | 191 | reserve_bootmem(CONFIG_MEMORY_START, PAGE_SIZE, BOOTMEM_DEFAULT); |
1da177e4 LT |
192 | |
193 | /* | |
194 | * reserve memory hole | |
195 | */ | |
196 | #ifdef CONFIG_MEMHOLE | |
72a7fe39 BW |
197 | reserve_bootmem(CONFIG_MEMHOLE_START, CONFIG_MEMHOLE_SIZE, |
198 | BOOTMEM_DEFAULT); | |
1da177e4 LT |
199 | #endif |
200 | ||
201 | #ifdef CONFIG_BLK_DEV_INITRD | |
202 | if (LOADER_TYPE && INITRD_START) { | |
203 | if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) { | |
72a7fe39 BW |
204 | reserve_bootmem(INITRD_START, INITRD_SIZE, |
205 | BOOTMEM_DEFAULT); | |
19e5d9c0 | 206 | initrd_start = INITRD_START + PAGE_OFFSET; |
1da177e4 LT |
207 | initrd_end = initrd_start + INITRD_SIZE; |
208 | printk("initrd:start[%08lx],size[%08lx]\n", | |
209 | initrd_start, INITRD_SIZE); | |
210 | } else { | |
211 | printk("initrd extends beyond end of memory " | |
212 | "(0x%08lx > 0x%08lx)\ndisabling initrd\n", | |
213 | INITRD_START + INITRD_SIZE, | |
214 | max_low_pfn << PAGE_SHIFT); | |
215 | ||
216 | initrd_start = 0; | |
217 | } | |
218 | } | |
219 | #endif | |
220 | ||
221 | return max_low_pfn; | |
222 | } | |
223 | #else /* CONFIG_DISCONTIGMEM */ | |
224 | extern unsigned long setup_memory(void); | |
225 | #endif /* CONFIG_DISCONTIGMEM */ | |
226 | ||
1da177e4 LT |
227 | void __init setup_arch(char **cmdline_p) |
228 | { | |
229 | ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV); | |
230 | ||
231 | boot_cpu_data.cpu_clock = M32R_CPUCLK; | |
232 | boot_cpu_data.bus_clock = M32R_BUSCLK; | |
233 | boot_cpu_data.timer_divide = M32R_TIMER_DIVIDE; | |
234 | ||
235 | #ifdef CONFIG_BLK_DEV_RAM | |
236 | rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK; | |
237 | rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0); | |
238 | rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0); | |
239 | #endif | |
240 | ||
241 | if (!MOUNT_ROOT_RDONLY) | |
242 | root_mountflags &= ~MS_RDONLY; | |
243 | ||
244 | #ifdef CONFIG_VT | |
245 | #if defined(CONFIG_VGA_CONSOLE) | |
246 | conswitchp = &vga_con; | |
247 | #elif defined(CONFIG_DUMMY_CONSOLE) | |
248 | conswitchp = &dummy_con; | |
249 | #endif | |
250 | #endif | |
251 | ||
252 | #ifdef CONFIG_DISCONTIGMEM | |
253 | nodes_clear(node_online_map); | |
254 | node_set_online(0); | |
255 | node_set_online(1); | |
256 | #endif /* CONFIG_DISCONTIGMEM */ | |
257 | ||
258 | init_mm.start_code = (unsigned long) _text; | |
259 | init_mm.end_code = (unsigned long) _etext; | |
260 | init_mm.end_data = (unsigned long) _edata; | |
261 | init_mm.brk = (unsigned long) _end; | |
262 | ||
263 | code_resource.start = virt_to_phys(_text); | |
264 | code_resource.end = virt_to_phys(_etext)-1; | |
265 | data_resource.start = virt_to_phys(_etext); | |
266 | data_resource.end = virt_to_phys(_edata)-1; | |
267 | ||
268 | parse_mem_cmdline(cmdline_p); | |
269 | ||
270 | setup_memory(); | |
271 | ||
272 | paging_init(); | |
273 | } | |
274 | ||
7c1c4e54 | 275 | static struct cpu cpu_devices[NR_CPUS]; |
1da177e4 LT |
276 | |
277 | static int __init topology_init(void) | |
278 | { | |
7c1c4e54 | 279 | int i; |
1da177e4 | 280 | |
7c1c4e54 | 281 | for_each_present_cpu(i) |
76b67ed9 | 282 | register_cpu(&cpu_devices[i], i); |
1da177e4 LT |
283 | |
284 | return 0; | |
285 | } | |
286 | ||
287 | subsys_initcall(topology_init); | |
288 | ||
289 | #ifdef CONFIG_PROC_FS | |
290 | /* | |
291 | * Get CPU information for use by the procfs. | |
292 | */ | |
293 | static int show_cpuinfo(struct seq_file *m, void *v) | |
294 | { | |
295 | struct cpuinfo_m32r *c = v; | |
296 | unsigned long cpu = c - cpu_data; | |
297 | ||
298 | #ifdef CONFIG_SMP | |
299 | if (!cpu_online(cpu)) | |
300 | return 0; | |
301 | #endif /* CONFIG_SMP */ | |
302 | ||
303 | seq_printf(m, "processor\t: %ld\n", cpu); | |
304 | ||
c978b017 | 305 | #if defined(CONFIG_CHIP_VDEC2) |
1da177e4 LT |
306 | seq_printf(m, "cpu family\t: VDEC2\n" |
307 | "cache size\t: Unknown\n"); | |
c978b017 | 308 | #elif defined(CONFIG_CHIP_M32700) |
1da177e4 LT |
309 | seq_printf(m,"cpu family\t: M32700\n" |
310 | "cache size\t: I-8KB/D-8KB\n"); | |
c978b017 | 311 | #elif defined(CONFIG_CHIP_M32102) |
1da177e4 LT |
312 | seq_printf(m,"cpu family\t: M32102\n" |
313 | "cache size\t: I-8KB\n"); | |
c978b017 | 314 | #elif defined(CONFIG_CHIP_OPSP) |
1da177e4 LT |
315 | seq_printf(m,"cpu family\t: OPSP\n" |
316 | "cache size\t: I-8KB/D-8KB\n"); | |
c978b017 | 317 | #elif defined(CONFIG_CHIP_MP) |
1da177e4 LT |
318 | seq_printf(m, "cpu family\t: M32R-MP\n" |
319 | "cache size\t: I-xxKB/D-xxKB\n"); | |
9287d95e HT |
320 | #elif defined(CONFIG_CHIP_M32104) |
321 | seq_printf(m,"cpu family\t: M32104\n" | |
322 | "cache size\t: I-8KB/D-8KB\n"); | |
1da177e4 LT |
323 | #else |
324 | seq_printf(m, "cpu family\t: Unknown\n"); | |
325 | #endif | |
326 | seq_printf(m, "bogomips\t: %lu.%02lu\n", | |
327 | c->loops_per_jiffy/(500000/HZ), | |
328 | (c->loops_per_jiffy/(5000/HZ)) % 100); | |
c978b017 | 329 | #if defined(CONFIG_PLAT_MAPPI) |
1da177e4 | 330 | seq_printf(m, "Machine\t\t: Mappi Evaluation board\n"); |
c978b017 | 331 | #elif defined(CONFIG_PLAT_MAPPI2) |
1da177e4 | 332 | seq_printf(m, "Machine\t\t: Mappi-II Evaluation board\n"); |
c978b017 | 333 | #elif defined(CONFIG_PLAT_MAPPI3) |
23680863 | 334 | seq_printf(m, "Machine\t\t: Mappi-III Evaluation board\n"); |
c978b017 | 335 | #elif defined(CONFIG_PLAT_M32700UT) |
1da177e4 | 336 | seq_printf(m, "Machine\t\t: M32700UT Evaluation board\n"); |
c978b017 | 337 | #elif defined(CONFIG_PLAT_OPSPUT) |
1da177e4 | 338 | seq_printf(m, "Machine\t\t: OPSPUT Evaluation board\n"); |
c978b017 | 339 | #elif defined(CONFIG_PLAT_USRV) |
1da177e4 | 340 | seq_printf(m, "Machine\t\t: uServer\n"); |
c978b017 | 341 | #elif defined(CONFIG_PLAT_OAKS32R) |
1da177e4 | 342 | seq_printf(m, "Machine\t\t: OAKS32R\n"); |
9287d95e HT |
343 | #elif defined(CONFIG_PLAT_M32104UT) |
344 | seq_printf(m, "Machine\t\t: M3T-M32104UT uT Engine board\n"); | |
1da177e4 LT |
345 | #else |
346 | seq_printf(m, "Machine\t\t: Unknown\n"); | |
347 | #endif | |
348 | ||
349 | #define PRINT_CLOCK(name, value) \ | |
350 | seq_printf(m, name " clock\t: %d.%02dMHz\n", \ | |
351 | ((value) / 1000000), ((value) % 1000000)/10000) | |
352 | ||
353 | PRINT_CLOCK("CPU", (int)c->cpu_clock); | |
354 | PRINT_CLOCK("Bus", (int)c->bus_clock); | |
355 | ||
356 | seq_printf(m, "\n"); | |
357 | ||
358 | return 0; | |
359 | } | |
360 | ||
361 | static void *c_start(struct seq_file *m, loff_t *pos) | |
362 | { | |
363 | return *pos < NR_CPUS ? cpu_data + *pos : NULL; | |
364 | } | |
365 | ||
366 | static void *c_next(struct seq_file *m, void *v, loff_t *pos) | |
367 | { | |
368 | ++*pos; | |
369 | return c_start(m, pos); | |
370 | } | |
371 | ||
372 | static void c_stop(struct seq_file *m, void *v) | |
373 | { | |
374 | } | |
375 | ||
03a44825 | 376 | const struct seq_operations cpuinfo_op = { |
7857a7f5 AV |
377 | .start = c_start, |
378 | .next = c_next, | |
379 | .stop = c_stop, | |
380 | .show = show_cpuinfo, | |
1da177e4 LT |
381 | }; |
382 | #endif /* CONFIG_PROC_FS */ | |
383 | ||
384 | unsigned long cpu_initialized __initdata = 0; | |
385 | ||
386 | /* | |
387 | * cpu_init() initializes state that is per-CPU. Some data is already | |
388 | * initialized (naturally) in the bootstrap process. | |
389 | * We reload them nevertheless, this function acts as a | |
390 | * 'CPU state barrier', nothing should get across. | |
391 | */ | |
392 | #if defined(CONFIG_CHIP_VDEC2) || defined(CONFIG_CHIP_XNUX2) \ | |
393 | || defined(CONFIG_CHIP_M32700) || defined(CONFIG_CHIP_M32102) \ | |
9287d95e | 394 | || defined(CONFIG_CHIP_OPSP) || defined(CONFIG_CHIP_M32104) |
1da177e4 LT |
395 | void __init cpu_init (void) |
396 | { | |
397 | int cpu_id = smp_processor_id(); | |
398 | ||
399 | if (test_and_set_bit(cpu_id, &cpu_initialized)) { | |
400 | printk(KERN_WARNING "CPU#%d already initialized!\n", cpu_id); | |
401 | for ( ; ; ) | |
402 | local_irq_enable(); | |
403 | } | |
404 | printk(KERN_INFO "Initializing CPU#%d\n", cpu_id); | |
405 | ||
406 | /* Set up and load the per-CPU TSS and LDT */ | |
f1f10076 | 407 | mmgrab(&init_mm); |
1da177e4 LT |
408 | current->active_mm = &init_mm; |
409 | if (current->mm) | |
410 | BUG(); | |
411 | ||
412 | /* Force FPU initialization */ | |
413 | current_thread_info()->status = 0; | |
414 | clear_used_math(); | |
415 | ||
416 | #ifdef CONFIG_MMU | |
417 | /* Set up MMU */ | |
418 | init_mmu(); | |
419 | #endif | |
420 | ||
421 | /* Set up ICUIMASK */ | |
422 | outl(0x00070000, M32R_ICU_IMASK_PORTL); /* imask=111 */ | |
423 | } | |
424 | #endif /* defined(CONFIG_CHIP_VDEC2) ... */ |