2 * linux/arch/unicore32/kernel/setup.c
4 * Code specific to PKUnity SoC and UniCore ISA
6 * Copyright (C) 2001-2010 GUAN Xue-tao
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.
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>
29 #include <linux/proc_fs.h>
30 #include <linux/elf.h>
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>
44 #define MEM_SIZE (16*1024*1024)
51 } ____cacheline_aligned;
53 static struct stack stacks[NR_CPUS];
55 #ifdef CONFIG_VGA_CONSOLE
56 struct screen_info screen_info;
59 char elf_platform[ELF_PLATFORM_SIZE];
60 EXPORT_SYMBOL(elf_platform);
62 static char __initdata cmd_line[COMMAND_LINE_SIZE];
64 static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
67 * Standard memory resources
69 static struct resource mem_res[] = {
71 .name = "Kernel code",
74 .flags = IORESOURCE_SYSTEM_RAM
77 .name = "Kernel data",
80 .flags = IORESOURCE_SYSTEM_RAM
84 #define kernel_code mem_res[0]
85 #define kernel_data mem_res[1]
88 * These functions re-use the assembly code in head.S, which
89 * already provide the required functionality.
91 static void __init setup_processor(void)
93 printk(KERN_DEFAULT "CPU: UniCore-II [%08x] revision %d, cr=%08lx\n",
94 uc32_cpuid, (int)(uc32_cpuid >> 16) & 15, cr_alignment);
96 sprintf(init_utsname()->machine, "puv3");
97 sprintf(elf_platform, "ucv2");
101 * cpu_init - initialise one CPU.
103 * cpu_init sets up the per-CPU stacks.
107 unsigned int cpu = smp_processor_id();
108 struct stack *stk = &stacks[cpu];
111 * setup stacks for re-entrant exception handlers
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)
133 static int __init uc32_add_memory(unsigned long start, unsigned long size)
135 struct membank *bank = &meminfo.bank[meminfo.nr_banks];
137 if (meminfo.nr_banks >= NR_BANKS) {
138 printk(KERN_CRIT "NR_BANKS too low, "
139 "ignoring memory at %#lx\n", start);
144 * Ensure that start/size are aligned to a page boundary.
145 * Size is appropriately rounded down, start is rounded up.
147 size -= start & ~PAGE_MASK;
149 bank->start = PAGE_ALIGN(start);
150 bank->size = size & PAGE_MASK;
153 * Check whether this memory region has non-zero size or
154 * invalid node number.
164 * Pick out the memory size. We look for mem=size@start,
165 * where start and size are "size[KkMm]"
167 static int __init early_mem(char *p)
169 static int usermem __initdata = 1;
170 unsigned long size, start;
174 * If the user specifies memory size, we
175 * blow away any automatically generated
180 meminfo.nr_banks = 0;
184 size = memparse(p, &endp);
186 start = memparse(endp + 1, NULL);
188 uc32_add_memory(start, size);
192 early_param("mem", early_mem);
195 request_standard_resources(struct meminfo *mi)
197 struct resource *res;
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);
205 for (i = 0; i < mi->nr_banks; i++) {
206 if (mi->bank[i].size == 0)
209 res = memblock_alloc_low(sizeof(*res), 0);
210 res->name = "System RAM";
211 res->start = mi->bank[i].start;
212 res->end = mi->bank[i].start + mi->bank[i].size - 1;
213 res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
215 request_resource(&iomem_resource, res);
217 if (kernel_code.start >= res->start &&
218 kernel_code.end <= res->end)
219 request_resource(res, &kernel_code);
220 if (kernel_data.start >= res->start &&
221 kernel_data.end <= res->end)
222 request_resource(res, &kernel_data);
226 static void (*init_machine)(void) __initdata;
228 static int __init customize_machine(void)
230 /* customizes platform devices, or adds new ones */
235 arch_initcall(customize_machine);
237 void __init setup_arch(char **cmdline_p)
239 char *from = default_command_line;
243 init_mm.start_code = (unsigned long) _stext;
244 init_mm.end_code = (unsigned long) _etext;
245 init_mm.end_data = (unsigned long) _edata;
246 init_mm.brk = (unsigned long) _end;
248 /* parse_early_param needs a boot_command_line */
249 strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
251 /* populate cmd_line too for later use, preserving boot_command_line */
252 strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
253 *cmdline_p = cmd_line;
257 uc32_memblock_init(&meminfo);
260 request_standard_resources(&meminfo);
265 * Set up various architecture-specific pointers
267 init_machine = puv3_core_init;
270 #if defined(CONFIG_VGA_CONSOLE)
271 conswitchp = &vga_con;
272 #elif defined(CONFIG_DUMMY_CONSOLE)
273 conswitchp = &dummy_con;
279 static struct cpu cpuinfo_unicore;
281 static int __init topology_init(void)
285 for_each_possible_cpu(i)
286 register_cpu(&cpuinfo_unicore, i);
290 subsys_initcall(topology_init);
292 #ifdef CONFIG_HAVE_PROC_CPU
293 static int __init proc_cpu_init(void)
295 struct proc_dir_entry *res;
297 res = proc_mkdir("cpu", NULL);
302 fs_initcall(proc_cpu_init);
305 static int c_show(struct seq_file *m, void *v)
307 seq_printf(m, "Processor\t: UniCore-II rev %d (%s)\n",
308 (int)(uc32_cpuid >> 16) & 15, elf_platform);
310 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
311 loops_per_jiffy / (500000/HZ),
312 (loops_per_jiffy / (5000/HZ)) % 100);
314 /* dump out the processor features */
315 seq_puts(m, "Features\t: CMOV UC-F64");
317 seq_printf(m, "\nCPU implementer\t: 0x%02x\n", uc32_cpuid >> 24);
318 seq_printf(m, "CPU architecture: 2\n");
319 seq_printf(m, "CPU revision\t: %d\n", (uc32_cpuid >> 16) & 15);
321 seq_printf(m, "Cache type\t: write-back\n"
322 "Cache clean\t: cp0 c5 ops\n"
323 "Cache lockdown\t: not support\n"
324 "Cache format\t: Harvard\n");
328 seq_printf(m, "Hardware\t: PKUnity v3\n");
333 static void *c_start(struct seq_file *m, loff_t *pos)
335 return *pos < 1 ? (void *)1 : NULL;
338 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
344 static void c_stop(struct seq_file *m, void *v)
348 const struct seq_operations cpuinfo_op = {