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