setup.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. /*
  2. * Port on Texas Instruments TMS320C6x architecture
  3. *
  4. * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
  5. * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/dma-mapping.h>
  12. #include <linux/memblock.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/clkdev.h>
  15. #include <linux/initrd.h>
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/of_fdt.h>
  19. #include <linux/string.h>
  20. #include <linux/errno.h>
  21. #include <linux/cache.h>
  22. #include <linux/delay.h>
  23. #include <linux/sched.h>
  24. #include <linux/clk.h>
  25. #include <linux/cpu.h>
  26. #include <linux/fs.h>
  27. #include <linux/of.h>
  28. #include <linux/console.h>
  29. #include <linux/screen_info.h>
  30. #include <asm/sections.h>
  31. #include <asm/div64.h>
  32. #include <asm/setup.h>
  33. #include <asm/dscr.h>
  34. #include <asm/clock.h>
  35. #include <asm/soc.h>
  36. #include <asm/special_insns.h>
  37. static const char *c6x_soc_name;
  38. struct screen_info screen_info;
  39. int c6x_num_cores;
  40. EXPORT_SYMBOL_GPL(c6x_num_cores);
  41. unsigned int c6x_silicon_rev;
  42. EXPORT_SYMBOL_GPL(c6x_silicon_rev);
  43. /*
  44. * Device status register. This holds information
  45. * about device configuration needed by some drivers.
  46. */
  47. unsigned int c6x_devstat;
  48. EXPORT_SYMBOL_GPL(c6x_devstat);
  49. /*
  50. * Some SoCs have fuse registers holding a unique MAC
  51. * address. This is parsed out of the device tree with
  52. * the resulting MAC being held here.
  53. */
  54. unsigned char c6x_fuse_mac[6];
  55. unsigned long memory_start;
  56. unsigned long memory_end;
  57. EXPORT_SYMBOL(memory_end);
  58. unsigned long ram_start;
  59. unsigned long ram_end;
  60. /* Uncached memory for DMA consistent use (memdma=) */
  61. static unsigned long dma_start __initdata;
  62. static unsigned long dma_size __initdata;
  63. struct cpuinfo_c6x {
  64. const char *cpu_name;
  65. const char *cpu_voltage;
  66. const char *mmu;
  67. const char *fpu;
  68. char *cpu_rev;
  69. unsigned int core_id;
  70. char __cpu_rev[5];
  71. };
  72. static DEFINE_PER_CPU(struct cpuinfo_c6x, cpu_data);
  73. unsigned int ticks_per_ns_scaled;
  74. EXPORT_SYMBOL(ticks_per_ns_scaled);
  75. unsigned int c6x_core_freq;
  76. static void __init get_cpuinfo(void)
  77. {
  78. unsigned cpu_id, rev_id, csr;
  79. struct clk *coreclk = clk_get_sys(NULL, "core");
  80. unsigned long core_khz;
  81. u64 tmp;
  82. struct cpuinfo_c6x *p;
  83. struct device_node *node;
  84. p = &per_cpu(cpu_data, smp_processor_id());
  85. if (!IS_ERR(coreclk))
  86. c6x_core_freq = clk_get_rate(coreclk);
  87. else {
  88. printk(KERN_WARNING
  89. "Cannot find core clock frequency. Using 700MHz\n");
  90. c6x_core_freq = 700000000;
  91. }
  92. core_khz = c6x_core_freq / 1000;
  93. tmp = (uint64_t)core_khz << C6X_NDELAY_SCALE;
  94. do_div(tmp, 1000000);
  95. ticks_per_ns_scaled = tmp;
  96. csr = get_creg(CSR);
  97. cpu_id = csr >> 24;
  98. rev_id = (csr >> 16) & 0xff;
  99. p->mmu = "none";
  100. p->fpu = "none";
  101. p->cpu_voltage = "unknown";
  102. switch (cpu_id) {
  103. case 0:
  104. p->cpu_name = "C67x";
  105. p->fpu = "yes";
  106. break;
  107. case 2:
  108. p->cpu_name = "C62x";
  109. break;
  110. case 8:
  111. p->cpu_name = "C64x";
  112. break;
  113. case 12:
  114. p->cpu_name = "C64x";
  115. break;
  116. case 16:
  117. p->cpu_name = "C64x+";
  118. p->cpu_voltage = "1.2";
  119. break;
  120. case 21:
  121. p->cpu_name = "C66X";
  122. p->cpu_voltage = "1.2";
  123. break;
  124. default:
  125. p->cpu_name = "unknown";
  126. break;
  127. }
  128. if (cpu_id < 16) {
  129. switch (rev_id) {
  130. case 0x1:
  131. if (cpu_id > 8) {
  132. p->cpu_rev = "DM640/DM641/DM642/DM643";
  133. p->cpu_voltage = "1.2 - 1.4";
  134. } else {
  135. p->cpu_rev = "C6201";
  136. p->cpu_voltage = "2.5";
  137. }
  138. break;
  139. case 0x2:
  140. p->cpu_rev = "C6201B/C6202/C6211";
  141. p->cpu_voltage = "1.8";
  142. break;
  143. case 0x3:
  144. p->cpu_rev = "C6202B/C6203/C6204/C6205";
  145. p->cpu_voltage = "1.5";
  146. break;
  147. case 0x201:
  148. p->cpu_rev = "C6701 revision 0 (early CPU)";
  149. p->cpu_voltage = "1.8";
  150. break;
  151. case 0x202:
  152. p->cpu_rev = "C6701/C6711/C6712";
  153. p->cpu_voltage = "1.8";
  154. break;
  155. case 0x801:
  156. p->cpu_rev = "C64x";
  157. p->cpu_voltage = "1.5";
  158. break;
  159. default:
  160. p->cpu_rev = "unknown";
  161. }
  162. } else {
  163. p->cpu_rev = p->__cpu_rev;
  164. snprintf(p->__cpu_rev, sizeof(p->__cpu_rev), "0x%x", cpu_id);
  165. }
  166. p->core_id = get_coreid();
  167. for_each_of_cpu_node(node)
  168. ++c6x_num_cores;
  169. node = of_find_node_by_name(NULL, "soc");
  170. if (node) {
  171. if (of_property_read_string(node, "model", &c6x_soc_name))
  172. c6x_soc_name = "unknown";
  173. of_node_put(node);
  174. } else
  175. c6x_soc_name = "unknown";
  176. printk(KERN_INFO "CPU%d: %s rev %s, %s volts, %uMHz\n",
  177. p->core_id, p->cpu_name, p->cpu_rev,
  178. p->cpu_voltage, c6x_core_freq / 1000000);
  179. }
  180. /*
  181. * Early parsing of the command line
  182. */
  183. static u32 mem_size __initdata;
  184. /* "mem=" parsing. */
  185. static int __init early_mem(char *p)
  186. {
  187. if (!p)
  188. return -EINVAL;
  189. mem_size = memparse(p, &p);
  190. /* don't remove all of memory when handling "mem={invalid}" */
  191. if (mem_size == 0)
  192. return -EINVAL;
  193. return 0;
  194. }
  195. early_param("mem", early_mem);
  196. /* "memdma=<size>[@<address>]" parsing. */
  197. static int __init early_memdma(char *p)
  198. {
  199. if (!p)
  200. return -EINVAL;
  201. dma_size = memparse(p, &p);
  202. if (*p == '@')
  203. dma_start = memparse(p, &p);
  204. return 0;
  205. }
  206. early_param("memdma", early_memdma);
  207. int __init c6x_add_memory(phys_addr_t start, unsigned long size)
  208. {
  209. static int ram_found __initdata;
  210. /* We only handle one bank (the one with PAGE_OFFSET) for now */
  211. if (ram_found)
  212. return -EINVAL;
  213. if (start > PAGE_OFFSET || PAGE_OFFSET >= (start + size))
  214. return 0;
  215. ram_start = start;
  216. ram_end = start + size;
  217. ram_found = 1;
  218. return 0;
  219. }
  220. /*
  221. * Do early machine setup and device tree parsing. This is called very
  222. * early on the boot process.
  223. */
  224. notrace void __init machine_init(unsigned long dt_ptr)
  225. {
  226. void *dtb = __va(dt_ptr);
  227. void *fdt = __dtb_start;
  228. /* interrupts must be masked */
  229. set_creg(IER, 2);
  230. /*
  231. * Set the Interrupt Service Table (IST) to the beginning of the
  232. * vector table.
  233. */
  234. set_ist(_vectors_start);
  235. /*
  236. * dtb is passed in from bootloader.
  237. * fdt is linked in blob.
  238. */
  239. if (dtb && dtb != fdt)
  240. fdt = dtb;
  241. /* Do some early initialization based on the flat device tree */
  242. early_init_dt_scan(fdt);
  243. parse_early_param();
  244. }
  245. void __init setup_arch(char **cmdline_p)
  246. {
  247. struct memblock_region *reg;
  248. printk(KERN_INFO "Initializing kernel\n");
  249. /* Initialize command line */
  250. *cmdline_p = boot_command_line;
  251. memory_end = ram_end;
  252. memory_end &= ~(PAGE_SIZE - 1);
  253. if (mem_size && (PAGE_OFFSET + PAGE_ALIGN(mem_size)) < memory_end)
  254. memory_end = PAGE_OFFSET + PAGE_ALIGN(mem_size);
  255. /* add block that this kernel can use */
  256. memblock_add(PAGE_OFFSET, memory_end - PAGE_OFFSET);
  257. /* reserve kernel text/data/bss */
  258. memblock_reserve(PAGE_OFFSET,
  259. PAGE_ALIGN((unsigned long)&_end - PAGE_OFFSET));
  260. if (dma_size) {
  261. /* align to cacheability granularity */
  262. dma_size = CACHE_REGION_END(dma_size);
  263. if (!dma_start)
  264. dma_start = memory_end - dma_size;
  265. /* align to cacheability granularity */
  266. dma_start = CACHE_REGION_START(dma_start);
  267. /* reserve DMA memory taken from kernel memory */
  268. if (memblock_is_region_memory(dma_start, dma_size))
  269. memblock_reserve(dma_start, dma_size);
  270. }
  271. memory_start = PAGE_ALIGN((unsigned int) &_end);
  272. printk(KERN_INFO "Memory Start=%08lx, Memory End=%08lx\n",
  273. memory_start, memory_end);
  274. #ifdef CONFIG_BLK_DEV_INITRD
  275. /*
  276. * Reserve initrd memory if in kernel memory.
  277. */
  278. if (initrd_start < initrd_end)
  279. if (memblock_is_region_memory(initrd_start,
  280. initrd_end - initrd_start))
  281. memblock_reserve(initrd_start,
  282. initrd_end - initrd_start);
  283. #endif
  284. init_mm.start_code = (unsigned long) &_stext;
  285. init_mm.end_code = (unsigned long) &_etext;
  286. init_mm.end_data = memory_start;
  287. init_mm.brk = memory_start;
  288. unflatten_and_copy_device_tree();
  289. c6x_cache_init();
  290. /* Set the whole external memory as non-cacheable */
  291. disable_caching(ram_start, ram_end - 1);
  292. /* Set caching of external RAM used by Linux */
  293. for_each_memblock(memory, reg)
  294. enable_caching(CACHE_REGION_START(reg->base),
  295. CACHE_REGION_START(reg->base + reg->size - 1));
  296. #ifdef CONFIG_BLK_DEV_INITRD
  297. /*
  298. * Enable caching for initrd which falls outside kernel memory.
  299. */
  300. if (initrd_start < initrd_end) {
  301. if (!memblock_is_region_memory(initrd_start,
  302. initrd_end - initrd_start))
  303. enable_caching(CACHE_REGION_START(initrd_start),
  304. CACHE_REGION_START(initrd_end - 1));
  305. }
  306. #endif
  307. /*
  308. * Disable caching for dma coherent memory taken from kernel memory.
  309. */
  310. if (dma_size && memblock_is_region_memory(dma_start, dma_size))
  311. disable_caching(dma_start,
  312. CACHE_REGION_START(dma_start + dma_size - 1));
  313. /* Initialize the coherent memory allocator */
  314. coherent_mem_init(dma_start, dma_size);
  315. max_low_pfn = PFN_DOWN(memory_end);
  316. min_low_pfn = PFN_UP(memory_start);
  317. max_pfn = max_low_pfn;
  318. max_mapnr = max_low_pfn - min_low_pfn;
  319. /* Get kmalloc into gear */
  320. paging_init();
  321. /*
  322. * Probe for Device State Configuration Registers.
  323. * We have to do this early in case timer needs to be enabled
  324. * through DSCR.
  325. */
  326. dscr_probe();
  327. /* We do this early for timer and core clock frequency */
  328. c64x_setup_clocks();
  329. /* Get CPU info */
  330. get_cpuinfo();
  331. #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
  332. conswitchp = &dummy_con;
  333. #endif
  334. }
  335. #define cpu_to_ptr(n) ((void *)((long)(n)+1))
  336. #define ptr_to_cpu(p) ((long)(p) - 1)
  337. static int show_cpuinfo(struct seq_file *m, void *v)
  338. {
  339. int n = ptr_to_cpu(v);
  340. struct cpuinfo_c6x *p = &per_cpu(cpu_data, n);
  341. if (n == 0) {
  342. seq_printf(m,
  343. "soc\t\t: %s\n"
  344. "soc revision\t: 0x%x\n"
  345. "soc cores\t: %d\n",
  346. c6x_soc_name, c6x_silicon_rev, c6x_num_cores);
  347. }
  348. seq_printf(m,
  349. "\n"
  350. "processor\t: %d\n"
  351. "cpu\t\t: %s\n"
  352. "core revision\t: %s\n"
  353. "core voltage\t: %s\n"
  354. "core id\t\t: %d\n"
  355. "mmu\t\t: %s\n"
  356. "fpu\t\t: %s\n"
  357. "cpu MHz\t\t: %u\n"
  358. "bogomips\t: %lu.%02lu\n\n",
  359. n,
  360. p->cpu_name, p->cpu_rev, p->cpu_voltage,
  361. p->core_id, p->mmu, p->fpu,
  362. (c6x_core_freq + 500000) / 1000000,
  363. (loops_per_jiffy/(500000/HZ)),
  364. (loops_per_jiffy/(5000/HZ))%100);
  365. return 0;
  366. }
  367. static void *c_start(struct seq_file *m, loff_t *pos)
  368. {
  369. return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
  370. }
  371. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  372. {
  373. ++*pos;
  374. return NULL;
  375. }
  376. static void c_stop(struct seq_file *m, void *v)
  377. {
  378. }
  379. const struct seq_operations cpuinfo_op = {
  380. c_start,
  381. c_stop,
  382. c_next,
  383. show_cpuinfo
  384. };
  385. static struct cpu cpu_devices[NR_CPUS];
  386. static int __init topology_init(void)
  387. {
  388. int i;
  389. for_each_present_cpu(i)
  390. register_cpu(&cpu_devices[i], i);
  391. return 0;
  392. }
  393. subsys_initcall(topology_init);