setup.c 7.5 KB

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