setup.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * arch/sh64/kernel/setup.c
  7. *
  8. * sh64 Arch Support
  9. *
  10. * This file handles the architecture-dependent parts of initialization
  11. *
  12. * Copyright (C) 2000, 2001 Paolo Alberelli
  13. * Copyright (C) 2003, 2004 Paul Mundt
  14. *
  15. * benedict.gaster@superh.com: 2nd May 2002
  16. * Modified to use the empty_zero_page to pass command line arguments.
  17. *
  18. * benedict.gaster@superh.com: 3rd May 2002
  19. * Added support for ramdisk, removing statically linked romfs at the same time.
  20. *
  21. * lethal@linux-sh.org: 15th May 2003
  22. * Added generic procfs cpuinfo reporting. Make boards just export their name.
  23. *
  24. * lethal@linux-sh.org: 25th May 2003
  25. * Added generic get_cpu_subtype() for subtype reporting from cpu_data->type.
  26. *
  27. */
  28. #include <linux/errno.h>
  29. #include <linux/rwsem.h>
  30. #include <linux/sched.h>
  31. #include <linux/kernel.h>
  32. #include <linux/mm.h>
  33. #include <linux/stddef.h>
  34. #include <linux/unistd.h>
  35. #include <linux/ptrace.h>
  36. #include <linux/slab.h>
  37. #include <linux/user.h>
  38. #include <linux/a.out.h>
  39. #include <linux/tty.h>
  40. #include <linux/ioport.h>
  41. #include <linux/delay.h>
  42. #include <linux/config.h>
  43. #include <linux/init.h>
  44. #include <linux/seq_file.h>
  45. #include <linux/blkdev.h>
  46. #include <linux/bootmem.h>
  47. #include <linux/console.h>
  48. #include <linux/root_dev.h>
  49. #include <linux/cpu.h>
  50. #include <linux/initrd.h>
  51. #include <asm/processor.h>
  52. #include <asm/page.h>
  53. #include <asm/pgtable.h>
  54. #include <asm/platform.h>
  55. #include <asm/uaccess.h>
  56. #include <asm/system.h>
  57. #include <asm/io.h>
  58. #include <asm/sections.h>
  59. #include <asm/setup.h>
  60. #include <asm/smp.h>
  61. #ifdef CONFIG_VT
  62. #include <linux/console.h>
  63. #endif
  64. struct screen_info screen_info;
  65. #ifdef CONFIG_BLK_DEV_RAM
  66. extern int rd_doload; /* 1 = load ramdisk, 0 = don't load */
  67. extern int rd_prompt; /* 1 = prompt for ramdisk, 0 = don't prompt */
  68. extern int rd_image_start; /* starting block # of image */
  69. #endif
  70. extern int root_mountflags;
  71. extern char *get_system_type(void);
  72. extern void platform_setup(void);
  73. extern void platform_monitor(void);
  74. extern void platform_reserve(void);
  75. extern int sh64_cache_init(void);
  76. extern int sh64_tlb_init(void);
  77. #define RAMDISK_IMAGE_START_MASK 0x07FF
  78. #define RAMDISK_PROMPT_FLAG 0x8000
  79. #define RAMDISK_LOAD_FLAG 0x4000
  80. static char command_line[COMMAND_LINE_SIZE] = { 0, };
  81. unsigned long long memory_start = CONFIG_MEMORY_START;
  82. unsigned long long memory_end = CONFIG_MEMORY_START + (CONFIG_MEMORY_SIZE_IN_MB * 1024 * 1024);
  83. struct sh_cpuinfo boot_cpu_data;
  84. static inline void parse_mem_cmdline (char ** cmdline_p)
  85. {
  86. char c = ' ', *to = command_line, *from = COMMAND_LINE;
  87. int len = 0;
  88. /* Save unparsed command line copy for /proc/cmdline */
  89. memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
  90. saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
  91. for (;;) {
  92. /*
  93. * "mem=XXX[kKmM]" defines a size of memory.
  94. */
  95. if (c == ' ' && !memcmp(from, "mem=", 4)) {
  96. if (to != command_line)
  97. to--;
  98. {
  99. unsigned long mem_size;
  100. mem_size = memparse(from+4, &from);
  101. memory_end = memory_start + mem_size;
  102. }
  103. }
  104. c = *(from++);
  105. if (!c)
  106. break;
  107. if (COMMAND_LINE_SIZE <= ++len)
  108. break;
  109. *(to++) = c;
  110. }
  111. *to = '\0';
  112. *cmdline_p = command_line;
  113. }
  114. static void __init sh64_cpu_type_detect(void)
  115. {
  116. extern unsigned long long peek_real_address_q(unsigned long long addr);
  117. unsigned long long cir;
  118. /* Do peeks in real mode to avoid having to set up a mapping for the
  119. WPC registers. On SH5-101 cut2, such a mapping would be exposed to
  120. an address translation erratum which would make it hard to set up
  121. correctly. */
  122. cir = peek_real_address_q(0x0d000008);
  123. if ((cir & 0xffff) == 0x5103) {
  124. boot_cpu_data.type = CPU_SH5_103;
  125. } else if (((cir >> 32) & 0xffff) == 0x51e2) {
  126. /* CPU.VCR aliased at CIR address on SH5-101 */
  127. boot_cpu_data.type = CPU_SH5_101;
  128. } else {
  129. boot_cpu_data.type = CPU_SH_NONE;
  130. }
  131. }
  132. void __init setup_arch(char **cmdline_p)
  133. {
  134. unsigned long bootmap_size, i;
  135. unsigned long first_pfn, start_pfn, last_pfn, pages;
  136. #ifdef CONFIG_EARLY_PRINTK
  137. extern void enable_early_printk(void);
  138. /*
  139. * Setup Early SCIF console
  140. */
  141. enable_early_printk();
  142. #endif
  143. /*
  144. * Setup TLB mappings
  145. */
  146. sh64_tlb_init();
  147. /*
  148. * Caches are already initialized by the time we get here, so we just
  149. * fill in cpu_data info for the caches.
  150. */
  151. sh64_cache_init();
  152. platform_setup();
  153. platform_monitor();
  154. sh64_cpu_type_detect();
  155. ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
  156. #ifdef CONFIG_BLK_DEV_RAM
  157. rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
  158. rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
  159. rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
  160. #endif
  161. if (!MOUNT_ROOT_RDONLY)
  162. root_mountflags &= ~MS_RDONLY;
  163. init_mm.start_code = (unsigned long) _text;
  164. init_mm.end_code = (unsigned long) _etext;
  165. init_mm.end_data = (unsigned long) _edata;
  166. init_mm.brk = (unsigned long) _end;
  167. code_resource.start = __pa(_text);
  168. code_resource.end = __pa(_etext)-1;
  169. data_resource.start = __pa(_etext);
  170. data_resource.end = __pa(_edata)-1;
  171. parse_mem_cmdline(cmdline_p);
  172. /*
  173. * Find the lowest and highest page frame numbers we have available
  174. */
  175. first_pfn = PFN_DOWN(memory_start);
  176. last_pfn = PFN_DOWN(memory_end);
  177. pages = last_pfn - first_pfn;
  178. /*
  179. * Partially used pages are not usable - thus
  180. * we are rounding upwards:
  181. */
  182. start_pfn = PFN_UP(__pa(_end));
  183. /*
  184. * Find a proper area for the bootmem bitmap. After this
  185. * bootstrap step all allocations (until the page allocator
  186. * is intact) must be done via bootmem_alloc().
  187. */
  188. bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
  189. first_pfn,
  190. last_pfn);
  191. /*
  192. * Round it up.
  193. */
  194. bootmap_size = PFN_PHYS(PFN_UP(bootmap_size));
  195. /*
  196. * Register fully available RAM pages with the bootmem allocator.
  197. */
  198. free_bootmem_node(NODE_DATA(0), PFN_PHYS(first_pfn), PFN_PHYS(pages));
  199. /*
  200. * Reserve all kernel sections + bootmem bitmap + a guard page.
  201. */
  202. reserve_bootmem_node(NODE_DATA(0), PFN_PHYS(first_pfn),
  203. (PFN_PHYS(start_pfn) + bootmap_size + PAGE_SIZE) - PFN_PHYS(first_pfn));
  204. /*
  205. * Reserve platform dependent sections
  206. */
  207. platform_reserve();
  208. #ifdef CONFIG_BLK_DEV_INITRD
  209. if (LOADER_TYPE && INITRD_START) {
  210. if (INITRD_START + INITRD_SIZE <= (PFN_PHYS(last_pfn))) {
  211. reserve_bootmem_node(NODE_DATA(0), INITRD_START + __MEMORY_START, INITRD_SIZE);
  212. initrd_start =
  213. (long) INITRD_START ? INITRD_START + PAGE_OFFSET + __MEMORY_START : 0;
  214. initrd_end = initrd_start + INITRD_SIZE;
  215. } else {
  216. printk("initrd extends beyond end of memory "
  217. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  218. (long) INITRD_START + INITRD_SIZE,
  219. PFN_PHYS(last_pfn));
  220. initrd_start = 0;
  221. }
  222. }
  223. #endif
  224. /*
  225. * Claim all RAM, ROM, and I/O resources.
  226. */
  227. /* Kernel RAM */
  228. request_resource(&iomem_resource, &code_resource);
  229. request_resource(&iomem_resource, &data_resource);
  230. /* Other KRAM space */
  231. for (i = 0; i < STANDARD_KRAM_RESOURCES - 2; i++)
  232. request_resource(&iomem_resource,
  233. &platform_parms.kram_res_p[i]);
  234. /* XRAM space */
  235. for (i = 0; i < STANDARD_XRAM_RESOURCES; i++)
  236. request_resource(&iomem_resource,
  237. &platform_parms.xram_res_p[i]);
  238. /* ROM space */
  239. for (i = 0; i < STANDARD_ROM_RESOURCES; i++)
  240. request_resource(&iomem_resource,
  241. &platform_parms.rom_res_p[i]);
  242. /* I/O space */
  243. for (i = 0; i < STANDARD_IO_RESOURCES; i++)
  244. request_resource(&ioport_resource,
  245. &platform_parms.io_res_p[i]);
  246. #ifdef CONFIG_VT
  247. #if defined(CONFIG_VGA_CONSOLE)
  248. conswitchp = &vga_con;
  249. #elif defined(CONFIG_DUMMY_CONSOLE)
  250. conswitchp = &dummy_con;
  251. #endif
  252. #endif
  253. printk("Hardware FPU: %s\n", fpu_in_use ? "enabled" : "disabled");
  254. paging_init();
  255. }
  256. void __xchg_called_with_bad_pointer(void)
  257. {
  258. printk(KERN_EMERG "xchg() called with bad pointer !\n");
  259. }
  260. static struct cpu cpu[1];
  261. static int __init topology_init(void)
  262. {
  263. return register_cpu(cpu, 0, NULL);
  264. }
  265. subsys_initcall(topology_init);
  266. /*
  267. * Get CPU information
  268. */
  269. static const char *cpu_name[] = {
  270. [CPU_SH5_101] = "SH5-101",
  271. [CPU_SH5_103] = "SH5-103",
  272. [CPU_SH_NONE] = "Unknown",
  273. };
  274. const char *get_cpu_subtype(void)
  275. {
  276. return cpu_name[boot_cpu_data.type];
  277. }
  278. #ifdef CONFIG_PROC_FS
  279. static int show_cpuinfo(struct seq_file *m,void *v)
  280. {
  281. unsigned int cpu = smp_processor_id();
  282. if (!cpu)
  283. seq_printf(m, "machine\t\t: %s\n", get_system_type());
  284. seq_printf(m, "processor\t: %d\n", cpu);
  285. seq_printf(m, "cpu family\t: SH-5\n");
  286. seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype());
  287. seq_printf(m, "icache size\t: %dK-bytes\n",
  288. (boot_cpu_data.icache.ways *
  289. boot_cpu_data.icache.sets *
  290. boot_cpu_data.icache.linesz) >> 10);
  291. seq_printf(m, "dcache size\t: %dK-bytes\n",
  292. (boot_cpu_data.dcache.ways *
  293. boot_cpu_data.dcache.sets *
  294. boot_cpu_data.dcache.linesz) >> 10);
  295. seq_printf(m, "itlb entries\t: %d\n", boot_cpu_data.itlb.entries);
  296. seq_printf(m, "dtlb entries\t: %d\n", boot_cpu_data.dtlb.entries);
  297. #define PRINT_CLOCK(name, value) \
  298. seq_printf(m, name " clock\t: %d.%02dMHz\n", \
  299. ((value) / 1000000), ((value) % 1000000)/10000)
  300. PRINT_CLOCK("cpu", boot_cpu_data.cpu_clock);
  301. PRINT_CLOCK("bus", boot_cpu_data.bus_clock);
  302. PRINT_CLOCK("module", boot_cpu_data.module_clock);
  303. seq_printf(m, "bogomips\t: %lu.%02lu\n\n",
  304. (loops_per_jiffy*HZ+2500)/500000,
  305. ((loops_per_jiffy*HZ+2500)/5000) % 100);
  306. return 0;
  307. }
  308. static void *c_start(struct seq_file *m, loff_t *pos)
  309. {
  310. return (void*)(*pos == 0);
  311. }
  312. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  313. {
  314. return NULL;
  315. }
  316. static void c_stop(struct seq_file *m, void *v)
  317. {
  318. }
  319. struct seq_operations cpuinfo_op = {
  320. .start = c_start,
  321. .next = c_next,
  322. .stop = c_stop,
  323. .show = show_cpuinfo,
  324. };
  325. #endif /* CONFIG_PROC_FS */