setup.c 11 KB

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