setup.c 11 KB

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