setup.c 7.6 KB

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