blob: 33c3bd1e5c6db1b03eef5b354495bc7a628541c5 [file] [log] [blame]
David Howellsb920de12008-02-08 04:19:31 -08001/* MN10300 Arch-specific initialisation
2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11#include <linux/errno.h>
12#include <linux/sched.h>
13#include <linux/kernel.h>
14#include <linux/mm.h>
15#include <linux/stddef.h>
16#include <linux/unistd.h>
17#include <linux/ptrace.h>
David Howellsb920de12008-02-08 04:19:31 -080018#include <linux/user.h>
David Howellsb920de12008-02-08 04:19:31 -080019#include <linux/tty.h>
20#include <linux/ioport.h>
21#include <linux/delay.h>
22#include <linux/init.h>
23#include <linux/bootmem.h>
24#include <linux/seq_file.h>
Akira Takeuchi368dd5a2010-10-27 17:28:55 +010025#include <linux/cpu.h>
David Howellsb920de12008-02-08 04:19:31 -080026#include <asm/processor.h>
27#include <linux/console.h>
28#include <asm/uaccess.h>
David Howellsb920de12008-02-08 04:19:31 -080029#include <asm/setup.h>
30#include <asm/io.h>
31#include <asm/smp.h>
David Howells2f2a2132009-04-10 14:33:48 +010032#include <proc/proc.h>
David Howellsb920de12008-02-08 04:19:31 -080033#include <asm/fpu.h>
34#include <asm/sections.h>
35
36struct mn10300_cpuinfo boot_cpu_data;
37
38/* For PCI or other memory-mapped resources */
39unsigned long pci_mem_start = 0x18000000;
40
41char redboot_command_line[COMMAND_LINE_SIZE] =
42 "console=ttyS0,115200 root=/dev/mtdblock3 rw";
43
44char __initdata redboot_platform_name[COMMAND_LINE_SIZE];
45
46static struct resource code_resource = {
47 .start = 0x100000,
48 .end = 0,
49 .name = "Kernel code",
50};
51
52static struct resource data_resource = {
53 .start = 0,
54 .end = 0,
55 .name = "Kernel data",
56};
57
58static unsigned long __initdata phys_memory_base;
59static unsigned long __initdata phys_memory_end;
60static unsigned long __initdata memory_end;
61unsigned long memory_size;
62
63struct thread_info *__current_ti = &init_thread_union.thread_info;
64struct task_struct *__current = &init_task;
65
Akira Takeuchi368dd5a2010-10-27 17:28:55 +010066#define mn10300_known_cpus 5
David Howellsb920de12008-02-08 04:19:31 -080067static const char *const mn10300_cputypes[] = {
Akira Takeuchi368dd5a2010-10-27 17:28:55 +010068 "am33-1",
69 "am33-2",
70 "am34-1",
71 "am33-3",
72 "am34-2",
David Howellsb920de12008-02-08 04:19:31 -080073 "unknown"
74};
75
76/*
77 *
78 */
79static void __init parse_mem_cmdline(char **cmdline_p)
80{
81 char *from, *to, c;
82
83 /* save unparsed command line copy for /proc/cmdline */
84 strcpy(boot_command_line, redboot_command_line);
85
86 /* see if there's an explicit memory size option */
87 from = redboot_command_line;
88 to = redboot_command_line;
89 c = ' ';
90
91 for (;;) {
92 if (c == ' ' && !memcmp(from, "mem=", 4)) {
93 if (to != redboot_command_line)
94 to--;
95 memory_size = memparse(from + 4, &from);
96 }
97
98 c = *(from++);
99 if (!c)
100 break;
101
102 *(to++) = c;
103 }
104
105 *to = '\0';
106 *cmdline_p = redboot_command_line;
107
108 if (memory_size == 0)
109 panic("Memory size not known\n");
110
111 memory_end = (unsigned long) CONFIG_KERNEL_RAM_BASE_ADDRESS +
112 memory_size;
113 if (memory_end > phys_memory_end)
114 memory_end = phys_memory_end;
115}
116
117/*
118 * architecture specific setup
119 */
120void __init setup_arch(char **cmdline_p)
121{
122 unsigned long bootmap_size;
123 unsigned long kstart_pfn, start_pfn, free_pfn, end_pfn;
124
125 cpu_init();
126 unit_setup();
Akira Takeuchi368dd5a2010-10-27 17:28:55 +0100127 smp_init_cpus();
David Howellsb920de12008-02-08 04:19:31 -0800128 parse_mem_cmdline(cmdline_p);
129
130 init_mm.start_code = (unsigned long)&_text;
131 init_mm.end_code = (unsigned long) &_etext;
132 init_mm.end_data = (unsigned long) &_edata;
133 init_mm.brk = (unsigned long) &_end;
134
135 code_resource.start = virt_to_bus(&_text);
136 code_resource.end = virt_to_bus(&_etext)-1;
137 data_resource.start = virt_to_bus(&_etext);
138 data_resource.end = virt_to_bus(&_edata)-1;
139
David Howellsb920de12008-02-08 04:19:31 -0800140 start_pfn = (CONFIG_KERNEL_RAM_BASE_ADDRESS >> PAGE_SHIFT);
141 kstart_pfn = PFN_UP(__pa(&_text));
142 free_pfn = PFN_UP(__pa(&_end));
143 end_pfn = PFN_DOWN(__pa(memory_end));
144
145 bootmap_size = init_bootmem_node(&contig_page_data,
146 free_pfn,
147 start_pfn,
148 end_pfn);
149
150 if (kstart_pfn > start_pfn)
151 free_bootmem(PFN_PHYS(start_pfn),
152 PFN_PHYS(kstart_pfn - start_pfn));
153
154 free_bootmem(PFN_PHYS(free_pfn),
155 PFN_PHYS(end_pfn - free_pfn));
156
157 /* If interrupt vector table is in main ram, then we need to
158 reserve the page it is occupying. */
159 if (CONFIG_INTERRUPT_VECTOR_BASE >= CONFIG_KERNEL_RAM_BASE_ADDRESS &&
160 CONFIG_INTERRUPT_VECTOR_BASE < memory_end)
Akira Takeuchic7f8d6f2008-12-10 12:43:39 +0000161 reserve_bootmem(CONFIG_INTERRUPT_VECTOR_BASE, PAGE_SIZE,
David Howellsb920de12008-02-08 04:19:31 -0800162 BOOTMEM_DEFAULT);
163
164 reserve_bootmem(PAGE_ALIGN(PFN_PHYS(free_pfn)), bootmap_size,
165 BOOTMEM_DEFAULT);
166
167#ifdef CONFIG_VT
168#if defined(CONFIG_VGA_CONSOLE)
169 conswitchp = &vga_con;
170#elif defined(CONFIG_DUMMY_CONSOLE)
171 conswitchp = &dummy_con;
172#endif
173#endif
174
175 paging_init();
176}
177
178/*
179 * perform CPU initialisation
180 */
181void __init cpu_init(void)
182{
183 unsigned long cpurev = CPUREV, type;
David Howellsb920de12008-02-08 04:19:31 -0800184
185 type = (CPUREV & CPUREV_TYPE) >> CPUREV_TYPE_S;
186 if (type > mn10300_known_cpus)
187 type = mn10300_known_cpus;
188
Akira Takeuchia5e03ca2010-10-27 17:29:00 +0100189 printk(KERN_INFO "Panasonic %s, rev %ld\n",
David Howellsb920de12008-02-08 04:19:31 -0800190 mn10300_cputypes[type],
191 (cpurev & CPUREV_REVISION) >> CPUREV_REVISION_S);
192
Akira Takeuchi368dd5a2010-10-27 17:28:55 +0100193 get_mem_info(&phys_memory_base, &memory_size);
David Howellsb920de12008-02-08 04:19:31 -0800194 phys_memory_end = phys_memory_base + memory_size;
195
David Howellsb920de12008-02-08 04:19:31 -0800196 fpu_init_state();
David Howellsb920de12008-02-08 04:19:31 -0800197}
198
Akira Takeuchi368dd5a2010-10-27 17:28:55 +0100199static struct cpu cpu_devices[NR_CPUS];
200
201static int __init topology_init(void)
202{
203 int i;
204
205 for_each_present_cpu(i)
206 register_cpu(&cpu_devices[i], i);
207
208 return 0;
209}
210
211subsys_initcall(topology_init);
212
David Howellsb920de12008-02-08 04:19:31 -0800213/*
214 * Get CPU information for use by the procfs.
215 */
216static int show_cpuinfo(struct seq_file *m, void *v)
217{
Akira Takeuchi368dd5a2010-10-27 17:28:55 +0100218#ifdef CONFIG_SMP
219 struct mn10300_cpuinfo *c = v;
220 unsigned long cpu_id = c - cpu_data;
221 unsigned long cpurev = c->type, type, icachesz, dcachesz;
222#else /* CONFIG_SMP */
223 unsigned long cpu_id = 0;
David Howellsb920de12008-02-08 04:19:31 -0800224 unsigned long cpurev = CPUREV, type, icachesz, dcachesz;
Akira Takeuchi368dd5a2010-10-27 17:28:55 +0100225#endif /* CONFIG_SMP */
David Howellsb920de12008-02-08 04:19:31 -0800226
Akira Takeuchi368dd5a2010-10-27 17:28:55 +0100227#ifdef CONFIG_SMP
228 if (!cpu_online(cpu_id))
229 return 0;
230#endif
231
232 type = (cpurev & CPUREV_TYPE) >> CPUREV_TYPE_S;
David Howellsb920de12008-02-08 04:19:31 -0800233 if (type > mn10300_known_cpus)
234 type = mn10300_known_cpus;
235
236 icachesz =
237 ((cpurev & CPUREV_ICWAY ) >> CPUREV_ICWAY_S) *
238 ((cpurev & CPUREV_ICSIZE) >> CPUREV_ICSIZE_S) *
239 1024;
240
241 dcachesz =
242 ((cpurev & CPUREV_DCWAY ) >> CPUREV_DCWAY_S) *
243 ((cpurev & CPUREV_DCSIZE) >> CPUREV_DCSIZE_S) *
244 1024;
245
246 seq_printf(m,
Akira Takeuchi368dd5a2010-10-27 17:28:55 +0100247 "processor : %ld\n"
Akira Takeuchia5e03ca2010-10-27 17:29:00 +0100248 "vendor_id : " PROCESSOR_VENDOR_NAME "\n"
David Howellsb920de12008-02-08 04:19:31 -0800249 "cpu core : %s\n"
250 "cpu rev : %lu\n"
251 "model name : " PROCESSOR_MODEL_NAME "\n"
252 "icache size: %lu\n"
253 "dcache size: %lu\n",
Akira Takeuchi368dd5a2010-10-27 17:28:55 +0100254 cpu_id,
David Howellsb920de12008-02-08 04:19:31 -0800255 mn10300_cputypes[type],
256 (cpurev & CPUREV_REVISION) >> CPUREV_REVISION_S,
257 icachesz,
258 dcachesz
259 );
260
261 seq_printf(m,
262 "ioclk speed: %lu.%02luMHz\n"
263 "bogomips : %lu.%02lu\n\n",
264 MN10300_IOCLK / 1000000,
265 (MN10300_IOCLK / 10000) % 100,
Akira Takeuchi368dd5a2010-10-27 17:28:55 +0100266#ifdef CONFIG_SMP
267 c->loops_per_jiffy / (500000 / HZ),
268 (c->loops_per_jiffy / (5000 / HZ)) % 100
269#else /* CONFIG_SMP */
David Howellsb920de12008-02-08 04:19:31 -0800270 loops_per_jiffy / (500000 / HZ),
271 (loops_per_jiffy / (5000 / HZ)) % 100
Akira Takeuchi368dd5a2010-10-27 17:28:55 +0100272#endif /* CONFIG_SMP */
David Howellsb920de12008-02-08 04:19:31 -0800273 );
274
275 return 0;
276}
277
278static void *c_start(struct seq_file *m, loff_t *pos)
279{
280 return *pos < NR_CPUS ? cpu_data + *pos : NULL;
281}
282
283static void *c_next(struct seq_file *m, void *v, loff_t *pos)
284{
285 ++*pos;
286 return c_start(m, pos);
287}
288
289static void c_stop(struct seq_file *m, void *v)
290{
291}
292
James Morris88e9d342009-09-22 16:43:43 -0700293const struct seq_operations cpuinfo_op = {
David Howellsb920de12008-02-08 04:19:31 -0800294 .start = c_start,
295 .next = c_next,
296 .stop = c_stop,
297 .show = show_cpuinfo,
298};