setup.c 9.7 KB

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