setup.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /* MN10300 Arch-specific initialisation
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/sched.h>
  13. #include <linux/kernel.h>
  14. #include <linux/mm.h>
  15. #include <linux/stddef.h>
  16. #include <linux/unistd.h>
  17. #include <linux/ptrace.h>
  18. #include <linux/slab.h>
  19. #include <linux/user.h>
  20. #include <linux/a.out.h>
  21. #include <linux/tty.h>
  22. #include <linux/ioport.h>
  23. #include <linux/delay.h>
  24. #include <linux/init.h>
  25. #include <linux/bootmem.h>
  26. #include <linux/seq_file.h>
  27. #include <asm/processor.h>
  28. #include <linux/console.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/system.h>
  31. #include <asm/setup.h>
  32. #include <asm/io.h>
  33. #include <asm/smp.h>
  34. #include <asm/proc/proc.h>
  35. #include <asm/busctl-regs.h>
  36. #include <asm/fpu.h>
  37. #include <asm/sections.h>
  38. struct mn10300_cpuinfo boot_cpu_data;
  39. /* For PCI or other memory-mapped resources */
  40. unsigned long pci_mem_start = 0x18000000;
  41. char redboot_command_line[COMMAND_LINE_SIZE] =
  42. "console=ttyS0,115200 root=/dev/mtdblock3 rw";
  43. char __initdata redboot_platform_name[COMMAND_LINE_SIZE];
  44. static struct resource code_resource = {
  45. .start = 0x100000,
  46. .end = 0,
  47. .name = "Kernel code",
  48. };
  49. static struct resource data_resource = {
  50. .start = 0,
  51. .end = 0,
  52. .name = "Kernel data",
  53. };
  54. static unsigned long __initdata phys_memory_base;
  55. static unsigned long __initdata phys_memory_end;
  56. static unsigned long __initdata memory_end;
  57. unsigned long memory_size;
  58. struct thread_info *__current_ti = &init_thread_union.thread_info;
  59. struct task_struct *__current = &init_task;
  60. #define mn10300_known_cpus 3
  61. static const char *const mn10300_cputypes[] = {
  62. "am33v1",
  63. "am33v2",
  64. "am34v1",
  65. "unknown"
  66. };
  67. /*
  68. *
  69. */
  70. static void __init parse_mem_cmdline(char **cmdline_p)
  71. {
  72. char *from, *to, c;
  73. /* save unparsed command line copy for /proc/cmdline */
  74. strcpy(boot_command_line, redboot_command_line);
  75. /* see if there's an explicit memory size option */
  76. from = redboot_command_line;
  77. to = redboot_command_line;
  78. c = ' ';
  79. for (;;) {
  80. if (c == ' ' && !memcmp(from, "mem=", 4)) {
  81. if (to != redboot_command_line)
  82. to--;
  83. memory_size = memparse(from + 4, &from);
  84. }
  85. c = *(from++);
  86. if (!c)
  87. break;
  88. *(to++) = c;
  89. }
  90. *to = '\0';
  91. *cmdline_p = redboot_command_line;
  92. if (memory_size == 0)
  93. panic("Memory size not known\n");
  94. memory_end = (unsigned long) CONFIG_KERNEL_RAM_BASE_ADDRESS +
  95. memory_size;
  96. if (memory_end > phys_memory_end)
  97. memory_end = phys_memory_end;
  98. }
  99. /*
  100. * architecture specific setup
  101. */
  102. void __init setup_arch(char **cmdline_p)
  103. {
  104. unsigned long bootmap_size;
  105. unsigned long kstart_pfn, start_pfn, free_pfn, end_pfn;
  106. cpu_init();
  107. unit_setup();
  108. parse_mem_cmdline(cmdline_p);
  109. init_mm.start_code = (unsigned long)&_text;
  110. init_mm.end_code = (unsigned long) &_etext;
  111. init_mm.end_data = (unsigned long) &_edata;
  112. init_mm.brk = (unsigned long) &_end;
  113. code_resource.start = virt_to_bus(&_text);
  114. code_resource.end = virt_to_bus(&_etext)-1;
  115. data_resource.start = virt_to_bus(&_etext);
  116. data_resource.end = virt_to_bus(&_edata)-1;
  117. #define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
  118. #define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
  119. #define PFN_PHYS(x) ((x) << PAGE_SHIFT)
  120. start_pfn = (CONFIG_KERNEL_RAM_BASE_ADDRESS >> PAGE_SHIFT);
  121. kstart_pfn = PFN_UP(__pa(&_text));
  122. free_pfn = PFN_UP(__pa(&_end));
  123. end_pfn = PFN_DOWN(__pa(memory_end));
  124. bootmap_size = init_bootmem_node(&contig_page_data,
  125. free_pfn,
  126. start_pfn,
  127. end_pfn);
  128. if (kstart_pfn > start_pfn)
  129. free_bootmem(PFN_PHYS(start_pfn),
  130. PFN_PHYS(kstart_pfn - start_pfn));
  131. free_bootmem(PFN_PHYS(free_pfn),
  132. PFN_PHYS(end_pfn - free_pfn));
  133. /* If interrupt vector table is in main ram, then we need to
  134. reserve the page it is occupying. */
  135. if (CONFIG_INTERRUPT_VECTOR_BASE >= CONFIG_KERNEL_RAM_BASE_ADDRESS &&
  136. CONFIG_INTERRUPT_VECTOR_BASE < memory_end)
  137. reserve_bootmem(CONFIG_INTERRUPT_VECTOR_BASE, 1,
  138. BOOTMEM_DEFAULT);
  139. reserve_bootmem(PAGE_ALIGN(PFN_PHYS(free_pfn)), bootmap_size,
  140. BOOTMEM_DEFAULT);
  141. #ifdef CONFIG_VT
  142. #if defined(CONFIG_VGA_CONSOLE)
  143. conswitchp = &vga_con;
  144. #elif defined(CONFIG_DUMMY_CONSOLE)
  145. conswitchp = &dummy_con;
  146. #endif
  147. #endif
  148. paging_init();
  149. }
  150. /*
  151. * perform CPU initialisation
  152. */
  153. void __init cpu_init(void)
  154. {
  155. unsigned long cpurev = CPUREV, type;
  156. unsigned long base, size;
  157. type = (CPUREV & CPUREV_TYPE) >> CPUREV_TYPE_S;
  158. if (type > mn10300_known_cpus)
  159. type = mn10300_known_cpus;
  160. printk(KERN_INFO "Matsushita %s, rev %ld\n",
  161. mn10300_cputypes[type],
  162. (cpurev & CPUREV_REVISION) >> CPUREV_REVISION_S);
  163. /* determine the memory size and base from the memory controller regs */
  164. memory_size = 0;
  165. base = SDBASE(0);
  166. if (base & SDBASE_CE) {
  167. size = (base & SDBASE_CBAM) << SDBASE_CBAM_SHIFT;
  168. size = ~size + 1;
  169. base &= SDBASE_CBA;
  170. printk(KERN_INFO "SDRAM[0]: %luMb @%08lx\n", size >> 20, base);
  171. memory_size += size;
  172. phys_memory_base = base;
  173. }
  174. base = SDBASE(1);
  175. if (base & SDBASE_CE) {
  176. size = (base & SDBASE_CBAM) << SDBASE_CBAM_SHIFT;
  177. size = ~size + 1;
  178. base &= SDBASE_CBA;
  179. printk(KERN_INFO "SDRAM[1]: %luMb @%08lx\n", size >> 20, base);
  180. memory_size += size;
  181. if (phys_memory_base == 0)
  182. phys_memory_base = base;
  183. }
  184. phys_memory_end = phys_memory_base + memory_size;
  185. #ifdef CONFIG_FPU
  186. fpu_init_state();
  187. #endif
  188. }
  189. /*
  190. * Get CPU information for use by the procfs.
  191. */
  192. static int show_cpuinfo(struct seq_file *m, void *v)
  193. {
  194. unsigned long cpurev = CPUREV, type, icachesz, dcachesz;
  195. type = (CPUREV & CPUREV_TYPE) >> CPUREV_TYPE_S;
  196. if (type > mn10300_known_cpus)
  197. type = mn10300_known_cpus;
  198. icachesz =
  199. ((cpurev & CPUREV_ICWAY ) >> CPUREV_ICWAY_S) *
  200. ((cpurev & CPUREV_ICSIZE) >> CPUREV_ICSIZE_S) *
  201. 1024;
  202. dcachesz =
  203. ((cpurev & CPUREV_DCWAY ) >> CPUREV_DCWAY_S) *
  204. ((cpurev & CPUREV_DCSIZE) >> CPUREV_DCSIZE_S) *
  205. 1024;
  206. seq_printf(m,
  207. "processor : 0\n"
  208. "vendor_id : Matsushita\n"
  209. "cpu core : %s\n"
  210. "cpu rev : %lu\n"
  211. "model name : " PROCESSOR_MODEL_NAME "\n"
  212. "icache size: %lu\n"
  213. "dcache size: %lu\n",
  214. mn10300_cputypes[type],
  215. (cpurev & CPUREV_REVISION) >> CPUREV_REVISION_S,
  216. icachesz,
  217. dcachesz
  218. );
  219. seq_printf(m,
  220. "ioclk speed: %lu.%02luMHz\n"
  221. "bogomips : %lu.%02lu\n\n",
  222. MN10300_IOCLK / 1000000,
  223. (MN10300_IOCLK / 10000) % 100,
  224. loops_per_jiffy / (500000 / HZ),
  225. (loops_per_jiffy / (5000 / HZ)) % 100
  226. );
  227. return 0;
  228. }
  229. static void *c_start(struct seq_file *m, loff_t *pos)
  230. {
  231. return *pos < NR_CPUS ? cpu_data + *pos : NULL;
  232. }
  233. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  234. {
  235. ++*pos;
  236. return c_start(m, pos);
  237. }
  238. static void c_stop(struct seq_file *m, void *v)
  239. {
  240. }
  241. struct seq_operations cpuinfo_op = {
  242. .start = c_start,
  243. .next = c_next,
  244. .stop = c_stop,
  245. .show = show_cpuinfo,
  246. };