setup.c 7.7 KB

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