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/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>
29 #include <linux/proc_fs.h>
30 #include <linux/memblock.h>
31 #include <linux/elf.h>
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>
44 #define MEM_SIZE (16*1024*1024)
51 } ____cacheline_aligned;
53 static struct stack stacks[NR_CPUS];
55 char elf_platform[ELF_PLATFORM_SIZE];
56 EXPORT_SYMBOL(elf_platform);
58 static char __initdata cmd_line[COMMAND_LINE_SIZE];
60 static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
63 * Standard memory resources
65 static struct resource mem_res[] = {
70 .flags = IORESOURCE_MEM
73 .name = "Kernel text",
76 .flags = IORESOURCE_MEM
79 .name = "Kernel data",
82 .flags = IORESOURCE_MEM
86 #define video_ram mem_res[0]
87 #define kernel_code mem_res[1]
88 #define kernel_data mem_res[2]
91 * These functions re-use the assembly code in head.S, which
92 * already provide the required functionality.
94 static void __init setup_processor(void)
96 printk(KERN_DEFAULT "CPU: UniCore-II [%08x] revision %d, cr=%08lx\n",
97 uc32_cpuid, (int)(uc32_cpuid >> 16) & 15, cr_alignment);
99 sprintf(init_utsname()->machine, "puv3");
100 sprintf(elf_platform, "ucv2");
104 * cpu_init - initialise one CPU.
106 * cpu_init sets up the per-CPU stacks.
110 unsigned int cpu = smp_processor_id();
111 struct stack *stk = &stacks[cpu];
114 * setup stacks for re-entrant exception handlers
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)
136 static int __init uc32_add_memory(unsigned long start, unsigned long size)
138 struct membank *bank = &meminfo.bank[meminfo.nr_banks];
140 if (meminfo.nr_banks >= NR_BANKS) {
141 printk(KERN_CRIT "NR_BANKS too low, "
142 "ignoring memory at %#lx\n", start);
147 * Ensure that start/size are aligned to a page boundary.
148 * Size is appropriately rounded down, start is rounded up.
150 size -= start & ~PAGE_MASK;
152 bank->start = PAGE_ALIGN(start);
153 bank->size = size & PAGE_MASK;
156 * Check whether this memory region has non-zero size or
157 * invalid node number.
167 * Pick out the memory size. We look for mem=size@start,
168 * where start and size are "size[KkMm]"
170 static int __init early_mem(char *p)
172 static int usermem __initdata = 1;
173 unsigned long size, start;
177 * If the user specifies memory size, we
178 * blow away any automatically generated
183 meminfo.nr_banks = 0;
187 size = memparse(p, &endp);
189 start = memparse(endp + 1, NULL);
191 uc32_add_memory(start, size);
195 early_param("mem", early_mem);
198 request_standard_resources(struct meminfo *mi)
200 struct resource *res;
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);
208 for (i = 0; i < mi->nr_banks; i++) {
209 if (mi->bank[i].size == 0)
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;
218 request_resource(&iomem_resource, res);
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);
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);
233 static void (*init_machine)(void) __initdata;
235 static int __init customize_machine(void)
237 /* customizes platform devices, or adds new ones */
242 arch_initcall(customize_machine);
244 void __init setup_arch(char **cmdline_p)
246 char *from = default_command_line;
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;
255 /* parse_early_param needs a boot_command_line */
256 strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
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;
264 uc32_memblock_init(&meminfo);
267 request_standard_resources(&meminfo);
272 * Set up various architecture-specific pointers
274 init_machine = puv3_core_init;
277 #if defined(CONFIG_VGA_CONSOLE)
278 conswitchp = &vga_con;
279 #elif defined(CONFIG_DUMMY_CONSOLE)
280 conswitchp = &dummy_con;
286 static struct cpu cpuinfo_unicore;
288 static int __init topology_init(void)
292 for_each_possible_cpu(i)
293 register_cpu(&cpuinfo_unicore, i);
297 subsys_initcall(topology_init);
299 #ifdef CONFIG_HAVE_PROC_CPU
300 static int __init proc_cpu_init(void)
302 struct proc_dir_entry *res;
304 res = proc_mkdir("cpu", NULL);
309 fs_initcall(proc_cpu_init);
312 static int c_show(struct seq_file *m, void *v)
314 seq_printf(m, "Processor\t: UniCore-II rev %d (%s)\n",
315 (int)(uc32_cpuid >> 16) & 15, elf_platform);
317 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
318 loops_per_jiffy / (500000/HZ),
319 (loops_per_jiffy / (5000/HZ)) % 100);
321 /* dump out the processor features */
322 seq_puts(m, "Features\t: CMOV UC-F64");
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);
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");
335 seq_printf(m, "Hardware\t: PKUnity v3\n");
340 static void *c_start(struct seq_file *m, loff_t *pos)
342 return *pos < 1 ? (void *)1 : NULL;
345 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
351 static void c_stop(struct seq_file *m, void *v)
355 const struct seq_operations cpuinfo_op = {