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