setup.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/h8300/kernel/setup.c
  4. *
  5. * Copyright (C) 2001-2014 Yoshinori Sato <ysato@users.sourceforge.jp>
  6. */
  7. /*
  8. * This file handles the architecture-dependent parts of system setup
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/sched.h>
  12. #include <linux/delay.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/mm.h>
  15. #include <linux/fs.h>
  16. #include <linux/console.h>
  17. #include <linux/errno.h>
  18. #include <linux/string.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/init.h>
  21. #include <linux/of.h>
  22. #include <linux/of_fdt.h>
  23. #include <linux/of_address.h>
  24. #include <linux/clk-provider.h>
  25. #include <linux/memblock.h>
  26. #include <linux/screen_info.h>
  27. #include <linux/clocksource.h>
  28. #include <asm/setup.h>
  29. #include <asm/irq.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/sections.h>
  32. #include <asm/page.h>
  33. #if defined(CONFIG_CPU_H8300H)
  34. #define CPU "H8/300H"
  35. #elif defined(CONFIG_CPU_H8S)
  36. #define CPU "H8S"
  37. #else
  38. #define CPU "Unknown"
  39. #endif
  40. unsigned long memory_start;
  41. unsigned long memory_end;
  42. EXPORT_SYMBOL(memory_end);
  43. static unsigned long freq;
  44. extern char __dtb_start[];
  45. #ifdef CONFIG_VT
  46. struct screen_info screen_info;
  47. #endif
  48. char __initdata command_line[COMMAND_LINE_SIZE];
  49. void sim_console_register(void);
  50. void __init h8300_fdt_init(void *fdt, char *bootargs)
  51. {
  52. if (!fdt)
  53. fdt = __dtb_start;
  54. else
  55. strcpy(command_line, bootargs);
  56. early_init_dt_scan(fdt);
  57. memblock_allow_resize();
  58. }
  59. static void __init bootmem_init(void)
  60. {
  61. struct memblock_region *region;
  62. memory_end = memory_start = 0;
  63. /* Find main memory where is the kernel */
  64. for_each_memblock(memory, region) {
  65. memory_start = region->base;
  66. memory_end = region->base + region->size;
  67. }
  68. if (!memory_end)
  69. panic("No memory!");
  70. /* setup bootmem globals (we use no_bootmem, but mm still depends on this) */
  71. min_low_pfn = PFN_UP(memory_start);
  72. max_low_pfn = PFN_DOWN(memblock_end_of_DRAM());
  73. max_pfn = max_low_pfn;
  74. memblock_reserve(__pa(_stext), _end - _stext);
  75. early_init_fdt_reserve_self();
  76. early_init_fdt_scan_reserved_mem();
  77. memblock_dump_all();
  78. }
  79. void __init setup_arch(char **cmdline_p)
  80. {
  81. unflatten_and_copy_device_tree();
  82. init_mm.start_code = (unsigned long) _stext;
  83. init_mm.end_code = (unsigned long) _etext;
  84. init_mm.end_data = (unsigned long) _edata;
  85. init_mm.brk = (unsigned long) 0;
  86. pr_notice("\r\n\nuClinux " CPU "\n");
  87. pr_notice("Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne\n");
  88. if (*command_line)
  89. strcpy(boot_command_line, command_line);
  90. *cmdline_p = boot_command_line;
  91. parse_early_param();
  92. bootmem_init();
  93. /*
  94. * get kmalloc into gear
  95. */
  96. paging_init();
  97. }
  98. /*
  99. * Get CPU information for use by the procfs.
  100. */
  101. static int show_cpuinfo(struct seq_file *m, void *v)
  102. {
  103. char *cpu;
  104. cpu = CPU;
  105. seq_printf(m, "CPU:\t\t%s\n"
  106. "Clock:\t\t%lu.%1luMHz\n"
  107. "BogoMips:\t%lu.%02lu\n"
  108. "Calibration:\t%lu loops\n",
  109. cpu,
  110. freq/1000, freq%1000,
  111. (loops_per_jiffy*HZ)/500000,
  112. ((loops_per_jiffy*HZ)/5000)%100,
  113. (loops_per_jiffy*HZ));
  114. return 0;
  115. }
  116. static void *c_start(struct seq_file *m, loff_t *pos)
  117. {
  118. return *pos < num_possible_cpus() ?
  119. ((void *) 0x12345678) : NULL;
  120. }
  121. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  122. {
  123. ++*pos;
  124. return c_start(m, pos);
  125. }
  126. static void c_stop(struct seq_file *m, void *v)
  127. {
  128. }
  129. const struct seq_operations cpuinfo_op = {
  130. .start = c_start,
  131. .next = c_next,
  132. .stop = c_stop,
  133. .show = show_cpuinfo,
  134. };
  135. #if defined(CONFIG_CPU_H8300H)
  136. #define get_wait(base, addr) ({ \
  137. int baddr; \
  138. baddr = ((addr) / 0x200000 * 2); \
  139. w *= (readw((base) + 2) & (3 << baddr)) + 1; \
  140. })
  141. #endif
  142. #if defined(CONFIG_CPU_H8S)
  143. #define get_wait(base, addr) ({ \
  144. int baddr; \
  145. baddr = ((addr) / 0x200000 * 16); \
  146. w *= (readl((base) + 2) & (7 << baddr)) + 1; \
  147. })
  148. #endif
  149. static __init int access_timing(void)
  150. {
  151. struct device_node *bsc;
  152. void __iomem *base;
  153. unsigned long addr = (unsigned long)&__delay;
  154. int bit = 1 << (addr / 0x200000);
  155. int w;
  156. bsc = of_find_compatible_node(NULL, NULL, "renesas,h8300-bsc");
  157. base = of_iomap(bsc, 0);
  158. w = (readb(base + 0) & bit)?2:1;
  159. if (readb(base + 1) & bit)
  160. w *= get_wait(base, addr);
  161. else
  162. w *= 2;
  163. return w * 3 / 2;
  164. }
  165. void __init calibrate_delay(void)
  166. {
  167. struct device_node *cpu;
  168. int freq;
  169. cpu = of_find_compatible_node(NULL, NULL, "renesas,h8300");
  170. of_property_read_s32(cpu, "clock-frequency", &freq);
  171. loops_per_jiffy = freq / HZ / (access_timing() * 2);
  172. pr_cont("%lu.%02lu BogoMIPS (lpj=%lu)\n",
  173. loops_per_jiffy / (500000 / HZ),
  174. (loops_per_jiffy / (5000 / HZ)) % 100, loops_per_jiffy);
  175. }
  176. void __init time_init(void)
  177. {
  178. of_clk_init(NULL);
  179. timer_probe();
  180. }