setup.c 10 KB

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