setup.c 5.4 KB

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