setup.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * linux/arch/h8300/kernel/setup.c
  3. *
  4. * Copyright (C) 2001-2014 Yoshinori Sato <ysato@users.sourceforge.jp>
  5. */
  6. /*
  7. * This file handles the architecture-dependent parts of system setup
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/delay.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/mm.h>
  14. #include <linux/fs.h>
  15. #include <linux/console.h>
  16. #include <linux/errno.h>
  17. #include <linux/string.h>
  18. #include <linux/bootmem.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/init.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/module.h>
  23. #include <linux/of.h>
  24. #include <linux/of_fdt.h>
  25. #include <linux/of_platform.h>
  26. #include <linux/of_address.h>
  27. #include <linux/clk-provider.h>
  28. #include <linux/memblock.h>
  29. #include <linux/screen_info.h>
  30. #include <linux/clocksource.h>
  31. #include <asm/setup.h>
  32. #include <asm/irq.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/sections.h>
  35. #include <asm/page.h>
  36. #if defined(CONFIG_CPU_H8300H)
  37. #define CPU "H8/300H"
  38. #elif defined(CONFIG_CPU_H8S)
  39. #define CPU "H8S"
  40. #else
  41. #define CPU "Unknown"
  42. #endif
  43. unsigned long memory_start;
  44. unsigned long memory_end;
  45. EXPORT_SYMBOL(memory_end);
  46. static unsigned long freq;
  47. extern char __dtb_start[];
  48. #ifdef CONFIG_VT
  49. struct screen_info screen_info;
  50. #endif
  51. char __initdata command_line[COMMAND_LINE_SIZE];
  52. void sim_console_register(void);
  53. void __init h8300_fdt_init(void *fdt, char *bootargs)
  54. {
  55. if (!fdt)
  56. fdt = __dtb_start;
  57. else
  58. strcpy(command_line, bootargs);
  59. early_init_dt_scan(fdt);
  60. memblock_allow_resize();
  61. }
  62. static void __init bootmem_init(void)
  63. {
  64. int bootmap_size;
  65. unsigned long ram_start_pfn;
  66. unsigned long free_ram_start_pfn;
  67. unsigned long ram_end_pfn;
  68. struct memblock_region *region;
  69. memory_end = memory_start = 0;
  70. /* Find main memory where is the kernel */
  71. for_each_memblock(memory, region) {
  72. memory_start = region->base;
  73. memory_end = region->base + region->size;
  74. }
  75. if (!memory_end)
  76. panic("No memory!");
  77. ram_start_pfn = PFN_UP(memory_start);
  78. /* free_ram_start_pfn is first page after kernel */
  79. free_ram_start_pfn = PFN_UP(__pa(_end));
  80. ram_end_pfn = PFN_DOWN(memblock_end_of_DRAM());
  81. max_pfn = ram_end_pfn;
  82. /*
  83. * give all the memory to the bootmap allocator, tell it to put the
  84. * boot mem_map at the start of memory
  85. */
  86. bootmap_size = init_bootmem_node(NODE_DATA(0),
  87. free_ram_start_pfn,
  88. 0,
  89. ram_end_pfn);
  90. /*
  91. * free the usable memory, we have to make sure we do not free
  92. * the bootmem bitmap so we then reserve it after freeing it :-)
  93. */
  94. free_bootmem(PFN_PHYS(free_ram_start_pfn),
  95. (ram_end_pfn - free_ram_start_pfn) << PAGE_SHIFT);
  96. reserve_bootmem(PFN_PHYS(free_ram_start_pfn), bootmap_size,
  97. BOOTMEM_DEFAULT);
  98. for_each_memblock(reserved, region) {
  99. reserve_bootmem(region->base, region->size, BOOTMEM_DEFAULT);
  100. }
  101. }
  102. void __init setup_arch(char **cmdline_p)
  103. {
  104. unflatten_and_copy_device_tree();
  105. init_mm.start_code = (unsigned long) _stext;
  106. init_mm.end_code = (unsigned long) _etext;
  107. init_mm.end_data = (unsigned long) _edata;
  108. init_mm.brk = (unsigned long) 0;
  109. pr_notice("\r\n\nuClinux " CPU "\n");
  110. pr_notice("Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne\n");
  111. if (*command_line)
  112. strcpy(boot_command_line, command_line);
  113. *cmdline_p = boot_command_line;
  114. parse_early_param();
  115. bootmem_init();
  116. #if defined(CONFIG_H8300H_SIM) || defined(CONFIG_H8S_SIM)
  117. sim_console_register();
  118. #endif
  119. early_platform_driver_probe("earlyprintk", 1, 0);
  120. /*
  121. * get kmalloc into gear
  122. */
  123. paging_init();
  124. }
  125. /*
  126. * Get CPU information for use by the procfs.
  127. */
  128. static int show_cpuinfo(struct seq_file *m, void *v)
  129. {
  130. char *cpu;
  131. cpu = CPU;
  132. seq_printf(m, "CPU:\t\t%s\n"
  133. "Clock:\t\t%lu.%1luMHz\n"
  134. "BogoMips:\t%lu.%02lu\n"
  135. "Calibration:\t%lu loops\n",
  136. cpu,
  137. freq/1000, freq%1000,
  138. (loops_per_jiffy*HZ)/500000,
  139. ((loops_per_jiffy*HZ)/5000)%100,
  140. (loops_per_jiffy*HZ));
  141. return 0;
  142. }
  143. static void *c_start(struct seq_file *m, loff_t *pos)
  144. {
  145. return *pos < num_possible_cpus() ?
  146. ((void *) 0x12345678) : NULL;
  147. }
  148. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  149. {
  150. ++*pos;
  151. return c_start(m, pos);
  152. }
  153. static void c_stop(struct seq_file *m, void *v)
  154. {
  155. }
  156. const struct seq_operations cpuinfo_op = {
  157. .start = c_start,
  158. .next = c_next,
  159. .stop = c_stop,
  160. .show = show_cpuinfo,
  161. };
  162. static int __init device_probe(void)
  163. {
  164. of_platform_populate(NULL, NULL, NULL, NULL);
  165. return 0;
  166. }
  167. device_initcall(device_probe);
  168. #if defined(CONFIG_CPU_H8300H)
  169. #define get_wait(base, addr) ({ \
  170. int baddr; \
  171. baddr = ((addr) / 0x200000 * 2); \
  172. w *= (ctrl_inw((unsigned long)(base) + 2) & (3 << baddr)) + 1; \
  173. })
  174. #endif
  175. #if defined(CONFIG_CPU_H8S)
  176. #define get_wait(base, addr) ({ \
  177. int baddr; \
  178. baddr = ((addr) / 0x200000 * 16); \
  179. w *= (ctrl_inl((unsigned long)(base) + 2) & (7 << baddr)) + 1; \
  180. })
  181. #endif
  182. static __init int access_timing(void)
  183. {
  184. struct device_node *bsc;
  185. void __iomem *base;
  186. unsigned long addr = (unsigned long)&__delay;
  187. int bit = 1 << (addr / 0x200000);
  188. int w;
  189. bsc = of_find_compatible_node(NULL, NULL, "renesas,h8300-bsc");
  190. base = of_iomap(bsc, 0);
  191. w = (ctrl_inb((unsigned long)base + 0) & bit)?2:1;
  192. if (ctrl_inb((unsigned long)base + 1) & bit)
  193. w *= get_wait(base, addr);
  194. else
  195. w *= 2;
  196. return w * 3 / 2;
  197. }
  198. void __init calibrate_delay(void)
  199. {
  200. struct device_node *cpu;
  201. int freq;
  202. cpu = of_find_compatible_node(NULL, NULL, "renesas,h8300");
  203. of_property_read_s32(cpu, "clock-frequency", &freq);
  204. loops_per_jiffy = freq / HZ / (access_timing() * 2);
  205. pr_cont("%lu.%02lu BogoMIPS (lpj=%lu)\n",
  206. loops_per_jiffy / (500000 / HZ),
  207. (loops_per_jiffy / (5000 / HZ)) % 100, loops_per_jiffy);
  208. }
  209. void __init time_init(void)
  210. {
  211. of_clk_init(NULL);
  212. clocksource_probe();
  213. }