setup.c 11 KB

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