setup.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /*
  2. * linux/arch/m32r/kernel/setup.c
  3. *
  4. * Setup routines for Renesas M32R
  5. *
  6. * Copyright (c) 2001, 2002 Hiroyuki Kondo, Hirokazu Takata,
  7. * Hitoshi Yamamoto
  8. */
  9. #include <linux/init.h>
  10. #include <linux/kernel.h>
  11. #include <linux/stddef.h>
  12. #include <linux/fs.h>
  13. #include <linux/sched.h>
  14. #include <linux/ioport.h>
  15. #include <linux/mm.h>
  16. #include <linux/bootmem.h>
  17. #include <linux/console.h>
  18. #include <linux/initrd.h>
  19. #include <linux/major.h>
  20. #include <linux/root_dev.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/timex.h>
  23. #include <linux/screen_info.h>
  24. #include <linux/cpu.h>
  25. #include <linux/nodemask.h>
  26. #include <linux/pfn.h>
  27. #include <asm/processor.h>
  28. #include <asm/pgtable.h>
  29. #include <asm/io.h>
  30. #include <asm/mmu_context.h>
  31. #include <asm/m32r.h>
  32. #include <asm/setup.h>
  33. #include <asm/sections.h>
  34. #ifdef CONFIG_MMU
  35. extern void init_mmu(void);
  36. #endif
  37. extern char _end[];
  38. /*
  39. * Machine setup..
  40. */
  41. struct cpuinfo_m32r boot_cpu_data;
  42. #ifdef CONFIG_BLK_DEV_RAM
  43. extern int rd_doload; /* 1 = load ramdisk, 0 = don't load */
  44. extern int rd_prompt; /* 1 = prompt for ramdisk, 0 = don't prompt */
  45. extern int rd_image_start; /* starting block # of image */
  46. #endif
  47. #if defined(CONFIG_VGA_CONSOLE)
  48. struct screen_info screen_info = {
  49. .orig_video_lines = 25,
  50. .orig_video_cols = 80,
  51. .orig_video_mode = 0,
  52. .orig_video_ega_bx = 0,
  53. .orig_video_isVGA = 1,
  54. .orig_video_points = 8
  55. };
  56. #endif
  57. extern int root_mountflags;
  58. static char __initdata command_line[COMMAND_LINE_SIZE];
  59. static struct resource data_resource = {
  60. .name = "Kernel data",
  61. .start = 0,
  62. .end = 0,
  63. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  64. };
  65. static struct resource code_resource = {
  66. .name = "Kernel code",
  67. .start = 0,
  68. .end = 0,
  69. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  70. };
  71. unsigned long memory_start;
  72. unsigned long memory_end;
  73. void __init setup_arch(char **);
  74. int get_cpuinfo(char *);
  75. static __inline__ void parse_mem_cmdline(char ** cmdline_p)
  76. {
  77. char c = ' ';
  78. char *to = command_line;
  79. char *from = COMMAND_LINE;
  80. int len = 0;
  81. int usermem = 0;
  82. /* Save unparsed command line copy for /proc/cmdline */
  83. memcpy(boot_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
  84. boot_command_line[COMMAND_LINE_SIZE-1] = '\0';
  85. memory_start = (unsigned long)CONFIG_MEMORY_START+PAGE_OFFSET;
  86. memory_end = memory_start+(unsigned long)CONFIG_MEMORY_SIZE;
  87. for ( ; ; ) {
  88. if (c == ' ' && !memcmp(from, "mem=", 4)) {
  89. if (to != command_line)
  90. to--;
  91. {
  92. unsigned long mem_size;
  93. usermem = 1;
  94. mem_size = memparse(from+4, &from);
  95. memory_end = memory_start + mem_size;
  96. }
  97. }
  98. c = *(from++);
  99. if (!c)
  100. break;
  101. if (COMMAND_LINE_SIZE <= ++len)
  102. break;
  103. *(to++) = c;
  104. }
  105. *to = '\0';
  106. *cmdline_p = command_line;
  107. if (usermem)
  108. printk(KERN_INFO "user-defined physical RAM map:\n");
  109. }
  110. #ifndef CONFIG_DISCONTIGMEM
  111. static unsigned long __init setup_memory(void)
  112. {
  113. unsigned long start_pfn, max_low_pfn, bootmap_size;
  114. start_pfn = PFN_UP( __pa(_end) );
  115. max_low_pfn = PFN_DOWN( __pa(memory_end) );
  116. /*
  117. * Initialize the boot-time allocator (with low memory only):
  118. */
  119. bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
  120. CONFIG_MEMORY_START>>PAGE_SHIFT, max_low_pfn);
  121. /*
  122. * Register fully available low RAM pages with the bootmem allocator.
  123. */
  124. {
  125. unsigned long curr_pfn;
  126. unsigned long last_pfn;
  127. unsigned long pages;
  128. /*
  129. * We are rounding up the start address of usable memory:
  130. */
  131. curr_pfn = PFN_UP(__pa(memory_start));
  132. /*
  133. * ... and at the end of the usable range downwards:
  134. */
  135. last_pfn = PFN_DOWN(__pa(memory_end));
  136. if (last_pfn > max_low_pfn)
  137. last_pfn = max_low_pfn;
  138. pages = last_pfn - curr_pfn;
  139. free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(pages));
  140. }
  141. /*
  142. * Reserve the kernel text and
  143. * Reserve the bootmem bitmap. We do this in two steps (first step
  144. * was init_bootmem()), because this catches the (definitely buggy)
  145. * case of us accidentally initializing the bootmem allocator with
  146. * an invalid RAM area.
  147. */
  148. reserve_bootmem(CONFIG_MEMORY_START + PAGE_SIZE,
  149. (PFN_PHYS(start_pfn) + bootmap_size + PAGE_SIZE - 1)
  150. - CONFIG_MEMORY_START,
  151. BOOTMEM_DEFAULT);
  152. /*
  153. * reserve physical page 0 - it's a special BIOS page on many boxes,
  154. * enabling clean reboots, SMP operation, laptop functions.
  155. */
  156. reserve_bootmem(CONFIG_MEMORY_START, PAGE_SIZE, BOOTMEM_DEFAULT);
  157. /*
  158. * reserve memory hole
  159. */
  160. #ifdef CONFIG_MEMHOLE
  161. reserve_bootmem(CONFIG_MEMHOLE_START, CONFIG_MEMHOLE_SIZE,
  162. BOOTMEM_DEFAULT);
  163. #endif
  164. #ifdef CONFIG_BLK_DEV_INITRD
  165. if (LOADER_TYPE && INITRD_START) {
  166. if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
  167. reserve_bootmem(INITRD_START, INITRD_SIZE,
  168. BOOTMEM_DEFAULT);
  169. initrd_start = INITRD_START + PAGE_OFFSET;
  170. initrd_end = initrd_start + INITRD_SIZE;
  171. printk("initrd:start[%08lx],size[%08lx]\n",
  172. initrd_start, INITRD_SIZE);
  173. } else {
  174. printk("initrd extends beyond end of memory "
  175. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  176. INITRD_START + INITRD_SIZE,
  177. max_low_pfn << PAGE_SHIFT);
  178. initrd_start = 0;
  179. }
  180. }
  181. #endif
  182. return max_low_pfn;
  183. }
  184. #else /* CONFIG_DISCONTIGMEM */
  185. extern unsigned long setup_memory(void);
  186. #endif /* CONFIG_DISCONTIGMEM */
  187. void __init setup_arch(char **cmdline_p)
  188. {
  189. ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
  190. boot_cpu_data.cpu_clock = M32R_CPUCLK;
  191. boot_cpu_data.bus_clock = M32R_BUSCLK;
  192. boot_cpu_data.timer_divide = M32R_TIMER_DIVIDE;
  193. #ifdef CONFIG_BLK_DEV_RAM
  194. rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
  195. rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
  196. rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
  197. #endif
  198. if (!MOUNT_ROOT_RDONLY)
  199. root_mountflags &= ~MS_RDONLY;
  200. #ifdef CONFIG_VT
  201. #if defined(CONFIG_VGA_CONSOLE)
  202. conswitchp = &vga_con;
  203. #elif defined(CONFIG_DUMMY_CONSOLE)
  204. conswitchp = &dummy_con;
  205. #endif
  206. #endif
  207. #ifdef CONFIG_DISCONTIGMEM
  208. nodes_clear(node_online_map);
  209. node_set_online(0);
  210. node_set_online(1);
  211. #endif /* CONFIG_DISCONTIGMEM */
  212. init_mm.start_code = (unsigned long) _text;
  213. init_mm.end_code = (unsigned long) _etext;
  214. init_mm.end_data = (unsigned long) _edata;
  215. init_mm.brk = (unsigned long) _end;
  216. code_resource.start = virt_to_phys(_text);
  217. code_resource.end = virt_to_phys(_etext)-1;
  218. data_resource.start = virt_to_phys(_etext);
  219. data_resource.end = virt_to_phys(_edata)-1;
  220. parse_mem_cmdline(cmdline_p);
  221. setup_memory();
  222. paging_init();
  223. }
  224. static struct cpu cpu_devices[NR_CPUS];
  225. static int __init topology_init(void)
  226. {
  227. int i;
  228. for_each_present_cpu(i)
  229. register_cpu(&cpu_devices[i], i);
  230. return 0;
  231. }
  232. subsys_initcall(topology_init);
  233. #ifdef CONFIG_PROC_FS
  234. /*
  235. * Get CPU information for use by the procfs.
  236. */
  237. static int show_cpuinfo(struct seq_file *m, void *v)
  238. {
  239. struct cpuinfo_m32r *c = v;
  240. unsigned long cpu = c - cpu_data;
  241. #ifdef CONFIG_SMP
  242. if (!cpu_online(cpu))
  243. return 0;
  244. #endif /* CONFIG_SMP */
  245. seq_printf(m, "processor\t: %ld\n", cpu);
  246. #if defined(CONFIG_CHIP_VDEC2)
  247. seq_printf(m, "cpu family\t: VDEC2\n"
  248. "cache size\t: Unknown\n");
  249. #elif defined(CONFIG_CHIP_M32700)
  250. seq_printf(m,"cpu family\t: M32700\n"
  251. "cache size\t: I-8KB/D-8KB\n");
  252. #elif defined(CONFIG_CHIP_M32102)
  253. seq_printf(m,"cpu family\t: M32102\n"
  254. "cache size\t: I-8KB\n");
  255. #elif defined(CONFIG_CHIP_OPSP)
  256. seq_printf(m,"cpu family\t: OPSP\n"
  257. "cache size\t: I-8KB/D-8KB\n");
  258. #elif defined(CONFIG_CHIP_MP)
  259. seq_printf(m, "cpu family\t: M32R-MP\n"
  260. "cache size\t: I-xxKB/D-xxKB\n");
  261. #elif defined(CONFIG_CHIP_M32104)
  262. seq_printf(m,"cpu family\t: M32104\n"
  263. "cache size\t: I-8KB/D-8KB\n");
  264. #else
  265. seq_printf(m, "cpu family\t: Unknown\n");
  266. #endif
  267. seq_printf(m, "bogomips\t: %lu.%02lu\n",
  268. c->loops_per_jiffy/(500000/HZ),
  269. (c->loops_per_jiffy/(5000/HZ)) % 100);
  270. #if defined(CONFIG_PLAT_MAPPI)
  271. seq_printf(m, "Machine\t\t: Mappi Evaluation board\n");
  272. #elif defined(CONFIG_PLAT_MAPPI2)
  273. seq_printf(m, "Machine\t\t: Mappi-II Evaluation board\n");
  274. #elif defined(CONFIG_PLAT_MAPPI3)
  275. seq_printf(m, "Machine\t\t: Mappi-III Evaluation board\n");
  276. #elif defined(CONFIG_PLAT_M32700UT)
  277. seq_printf(m, "Machine\t\t: M32700UT Evaluation board\n");
  278. #elif defined(CONFIG_PLAT_OPSPUT)
  279. seq_printf(m, "Machine\t\t: OPSPUT Evaluation board\n");
  280. #elif defined(CONFIG_PLAT_USRV)
  281. seq_printf(m, "Machine\t\t: uServer\n");
  282. #elif defined(CONFIG_PLAT_OAKS32R)
  283. seq_printf(m, "Machine\t\t: OAKS32R\n");
  284. #elif defined(CONFIG_PLAT_M32104UT)
  285. seq_printf(m, "Machine\t\t: M3T-M32104UT uT Engine board\n");
  286. #else
  287. seq_printf(m, "Machine\t\t: Unknown\n");
  288. #endif
  289. #define PRINT_CLOCK(name, value) \
  290. seq_printf(m, name " clock\t: %d.%02dMHz\n", \
  291. ((value) / 1000000), ((value) % 1000000)/10000)
  292. PRINT_CLOCK("CPU", (int)c->cpu_clock);
  293. PRINT_CLOCK("Bus", (int)c->bus_clock);
  294. seq_printf(m, "\n");
  295. return 0;
  296. }
  297. static void *c_start(struct seq_file *m, loff_t *pos)
  298. {
  299. return *pos < NR_CPUS ? cpu_data + *pos : NULL;
  300. }
  301. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  302. {
  303. ++*pos;
  304. return c_start(m, pos);
  305. }
  306. static void c_stop(struct seq_file *m, void *v)
  307. {
  308. }
  309. const struct seq_operations cpuinfo_op = {
  310. .start = c_start,
  311. .next = c_next,
  312. .stop = c_stop,
  313. .show = show_cpuinfo,
  314. };
  315. #endif /* CONFIG_PROC_FS */
  316. unsigned long cpu_initialized __initdata = 0;
  317. /*
  318. * cpu_init() initializes state that is per-CPU. Some data is already
  319. * initialized (naturally) in the bootstrap process.
  320. * We reload them nevertheless, this function acts as a
  321. * 'CPU state barrier', nothing should get across.
  322. */
  323. #if defined(CONFIG_CHIP_VDEC2) || defined(CONFIG_CHIP_XNUX2) \
  324. || defined(CONFIG_CHIP_M32700) || defined(CONFIG_CHIP_M32102) \
  325. || defined(CONFIG_CHIP_OPSP) || defined(CONFIG_CHIP_M32104)
  326. void __init cpu_init (void)
  327. {
  328. int cpu_id = smp_processor_id();
  329. if (test_and_set_bit(cpu_id, &cpu_initialized)) {
  330. printk(KERN_WARNING "CPU#%d already initialized!\n", cpu_id);
  331. for ( ; ; )
  332. local_irq_enable();
  333. }
  334. printk(KERN_INFO "Initializing CPU#%d\n", cpu_id);
  335. /* Set up and load the per-CPU TSS and LDT */
  336. atomic_inc(&init_mm.mm_count);
  337. current->active_mm = &init_mm;
  338. if (current->mm)
  339. BUG();
  340. /* Force FPU initialization */
  341. current_thread_info()->status = 0;
  342. clear_used_math();
  343. #ifdef CONFIG_MMU
  344. /* Set up MMU */
  345. init_mmu();
  346. #endif
  347. /* Set up ICUIMASK */
  348. outl(0x00070000, M32R_ICU_IMASK_PORTL); /* imask=111 */
  349. }
  350. #endif /* defined(CONFIG_CHIP_VDEC2) ... */