setup.c 11 KB

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