Merge branch 'for-2.6.39/drivers' of git://git.kernel.dk/linux-2.6-block
[pandora-kernel.git] / arch / unicore32 / kernel / setup.c
1 /*
2  * linux/arch/unicore32/kernel/setup.c
3  *
4  * Code specific to PKUnity SoC and UniCore ISA
5  *
6  * Copyright (C) 2001-2010 GUAN Xue-tao
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/stddef.h>
15 #include <linux/ioport.h>
16 #include <linux/delay.h>
17 #include <linux/utsname.h>
18 #include <linux/initrd.h>
19 #include <linux/console.h>
20 #include <linux/bootmem.h>
21 #include <linux/seq_file.h>
22 #include <linux/screen_info.h>
23 #include <linux/init.h>
24 #include <linux/root_dev.h>
25 #include <linux/cpu.h>
26 #include <linux/interrupt.h>
27 #include <linux/smp.h>
28 #include <linux/fs.h>
29 #include <linux/proc_fs.h>
30 #include <linux/memblock.h>
31 #include <linux/elf.h>
32 #include <linux/io.h>
33
34 #include <asm/cputype.h>
35 #include <asm/sections.h>
36 #include <asm/setup.h>
37 #include <asm/cacheflush.h>
38 #include <asm/tlbflush.h>
39 #include <asm/traps.h>
40
41 #include "setup.h"
42
43 #ifndef MEM_SIZE
44 #define MEM_SIZE        (16*1024*1024)
45 #endif
46
47 struct stack {
48         u32 irq[3];
49         u32 abt[3];
50         u32 und[3];
51 } ____cacheline_aligned;
52
53 static struct stack stacks[NR_CPUS];
54
55 char elf_platform[ELF_PLATFORM_SIZE];
56 EXPORT_SYMBOL(elf_platform);
57
58 static char __initdata cmd_line[COMMAND_LINE_SIZE];
59
60 static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
61
62 /*
63  * Standard memory resources
64  */
65 static struct resource mem_res[] = {
66         {
67                 .name = "Video RAM",
68                 .start = 0,
69                 .end = 0,
70                 .flags = IORESOURCE_MEM
71         },
72         {
73                 .name = "Kernel text",
74                 .start = 0,
75                 .end = 0,
76                 .flags = IORESOURCE_MEM
77         },
78         {
79                 .name = "Kernel data",
80                 .start = 0,
81                 .end = 0,
82                 .flags = IORESOURCE_MEM
83         }
84 };
85
86 #define video_ram   mem_res[0]
87 #define kernel_code mem_res[1]
88 #define kernel_data mem_res[2]
89
90 /*
91  * These functions re-use the assembly code in head.S, which
92  * already provide the required functionality.
93  */
94 static void __init setup_processor(void)
95 {
96         printk(KERN_DEFAULT "CPU: UniCore-II [%08x] revision %d, cr=%08lx\n",
97                uc32_cpuid, (int)(uc32_cpuid >> 16) & 15, cr_alignment);
98
99         sprintf(init_utsname()->machine, "puv3");
100         sprintf(elf_platform, "ucv2");
101 }
102
103 /*
104  * cpu_init - initialise one CPU.
105  *
106  * cpu_init sets up the per-CPU stacks.
107  */
108 void cpu_init(void)
109 {
110         unsigned int cpu = smp_processor_id();
111         struct stack *stk = &stacks[cpu];
112
113         /*
114          * setup stacks for re-entrant exception handlers
115          */
116         __asm__ (
117         "mov.a  asr, %1\n\t"
118         "add    sp, %0, %2\n\t"
119         "mov.a  asr, %3\n\t"
120         "add    sp, %0, %4\n\t"
121         "mov.a  asr, %5\n\t"
122         "add    sp, %0, %6\n\t"
123         "mov.a  asr, %7"
124             :
125             : "r" (stk),
126               "r" (PSR_R_BIT | PSR_I_BIT | INTR_MODE),
127               "I" (offsetof(struct stack, irq[0])),
128               "r" (PSR_R_BIT | PSR_I_BIT | ABRT_MODE),
129               "I" (offsetof(struct stack, abt[0])),
130               "r" (PSR_R_BIT | PSR_I_BIT | EXTN_MODE),
131               "I" (offsetof(struct stack, und[0])),
132               "r" (PSR_R_BIT | PSR_I_BIT | PRIV_MODE)
133         : "r30", "cc");
134 }
135
136 static int __init uc32_add_memory(unsigned long start, unsigned long size)
137 {
138         struct membank *bank = &meminfo.bank[meminfo.nr_banks];
139
140         if (meminfo.nr_banks >= NR_BANKS) {
141                 printk(KERN_CRIT "NR_BANKS too low, "
142                         "ignoring memory at %#lx\n", start);
143                 return -EINVAL;
144         }
145
146         /*
147          * Ensure that start/size are aligned to a page boundary.
148          * Size is appropriately rounded down, start is rounded up.
149          */
150         size -= start & ~PAGE_MASK;
151
152         bank->start = PAGE_ALIGN(start);
153         bank->size  = size & PAGE_MASK;
154
155         /*
156          * Check whether this memory region has non-zero size or
157          * invalid node number.
158          */
159         if (bank->size == 0)
160                 return -EINVAL;
161
162         meminfo.nr_banks++;
163         return 0;
164 }
165
166 /*
167  * Pick out the memory size.  We look for mem=size@start,
168  * where start and size are "size[KkMm]"
169  */
170 static int __init early_mem(char *p)
171 {
172         static int usermem __initdata = 1;
173         unsigned long size, start;
174         char *endp;
175
176         /*
177          * If the user specifies memory size, we
178          * blow away any automatically generated
179          * size.
180          */
181         if (usermem) {
182                 usermem = 0;
183                 meminfo.nr_banks = 0;
184         }
185
186         start = PHYS_OFFSET;
187         size  = memparse(p, &endp);
188         if (*endp == '@')
189                 start = memparse(endp + 1, NULL);
190
191         uc32_add_memory(start, size);
192
193         return 0;
194 }
195 early_param("mem", early_mem);
196
197 static void __init
198 request_standard_resources(struct meminfo *mi)
199 {
200         struct resource *res;
201         int i;
202
203         kernel_code.start   = virt_to_phys(_stext);
204         kernel_code.end     = virt_to_phys(_etext - 1);
205         kernel_data.start   = virt_to_phys(_sdata);
206         kernel_data.end     = virt_to_phys(_end - 1);
207
208         for (i = 0; i < mi->nr_banks; i++) {
209                 if (mi->bank[i].size == 0)
210                         continue;
211
212                 res = alloc_bootmem_low(sizeof(*res));
213                 res->name  = "System RAM";
214                 res->start = mi->bank[i].start;
215                 res->end   = mi->bank[i].start + mi->bank[i].size - 1;
216                 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
217
218                 request_resource(&iomem_resource, res);
219
220                 if (kernel_code.start >= res->start &&
221                     kernel_code.end <= res->end)
222                         request_resource(res, &kernel_code);
223                 if (kernel_data.start >= res->start &&
224                     kernel_data.end <= res->end)
225                         request_resource(res, &kernel_data);
226         }
227
228         video_ram.start = PKUNITY_UNIGFX_MMAP_BASE;
229         video_ram.end   = PKUNITY_UNIGFX_MMAP_BASE + PKUNITY_UNIGFX_MMAP_SIZE;
230         request_resource(&iomem_resource, &video_ram);
231 }
232
233 static void (*init_machine)(void) __initdata;
234
235 static int __init customize_machine(void)
236 {
237         /* customizes platform devices, or adds new ones */
238         if (init_machine)
239                 init_machine();
240         return 0;
241 }
242 arch_initcall(customize_machine);
243
244 void __init setup_arch(char **cmdline_p)
245 {
246         char *from = default_command_line;
247
248         setup_processor();
249
250         init_mm.start_code = (unsigned long) _stext;
251         init_mm.end_code   = (unsigned long) _etext;
252         init_mm.end_data   = (unsigned long) _edata;
253         init_mm.brk        = (unsigned long) _end;
254
255         /* parse_early_param needs a boot_command_line */
256         strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
257
258         /* populate cmd_line too for later use, preserving boot_command_line */
259         strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
260         *cmdline_p = cmd_line;
261
262         parse_early_param();
263
264         uc32_memblock_init(&meminfo);
265
266         paging_init();
267         request_standard_resources(&meminfo);
268
269         cpu_init();
270
271         /*
272          * Set up various architecture-specific pointers
273          */
274         init_machine = puv3_core_init;
275
276 #ifdef CONFIG_VT
277 #if defined(CONFIG_VGA_CONSOLE)
278         conswitchp = &vga_con;
279 #elif defined(CONFIG_DUMMY_CONSOLE)
280         conswitchp = &dummy_con;
281 #endif
282 #endif
283         early_trap_init();
284 }
285
286 static struct cpu cpuinfo_unicore;
287
288 static int __init topology_init(void)
289 {
290         int i;
291
292         for_each_possible_cpu(i)
293                 register_cpu(&cpuinfo_unicore, i);
294
295         return 0;
296 }
297 subsys_initcall(topology_init);
298
299 #ifdef CONFIG_HAVE_PROC_CPU
300 static int __init proc_cpu_init(void)
301 {
302         struct proc_dir_entry *res;
303
304         res = proc_mkdir("cpu", NULL);
305         if (!res)
306                 return -ENOMEM;
307         return 0;
308 }
309 fs_initcall(proc_cpu_init);
310 #endif
311
312 static int c_show(struct seq_file *m, void *v)
313 {
314         seq_printf(m, "Processor\t: UniCore-II rev %d (%s)\n",
315                    (int)(uc32_cpuid >> 16) & 15, elf_platform);
316
317         seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
318                    loops_per_jiffy / (500000/HZ),
319                    (loops_per_jiffy / (5000/HZ)) % 100);
320
321         /* dump out the processor features */
322         seq_puts(m, "Features\t: CMOV UC-F64");
323
324         seq_printf(m, "\nCPU implementer\t: 0x%02x\n", uc32_cpuid >> 24);
325         seq_printf(m, "CPU architecture: 2\n");
326         seq_printf(m, "CPU revision\t: %d\n", (uc32_cpuid >> 16) & 15);
327
328         seq_printf(m, "Cache type\t: write-back\n"
329                         "Cache clean\t: cp0 c5 ops\n"
330                         "Cache lockdown\t: not support\n"
331                         "Cache format\t: Harvard\n");
332
333         seq_puts(m, "\n");
334
335         seq_printf(m, "Hardware\t: PKUnity v3\n");
336
337         return 0;
338 }
339
340 static void *c_start(struct seq_file *m, loff_t *pos)
341 {
342         return *pos < 1 ? (void *)1 : NULL;
343 }
344
345 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
346 {
347         ++*pos;
348         return NULL;
349 }
350
351 static void c_stop(struct seq_file *m, void *v)
352 {
353 }
354
355 const struct seq_operations cpuinfo_op = {
356         .start  = c_start,
357         .next   = c_next,
358         .stop   = c_stop,
359         .show   = c_show
360 };