setup.c 5.6 KB

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