setup.c 11 KB

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