setup.c 4.6 KB

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