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