setup.c 9.7 KB

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