setup.c 7.5 KB

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