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 <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. static const char *c6x_soc_name;
  36. int c6x_num_cores;
  37. EXPORT_SYMBOL_GPL(c6x_num_cores);
  38. unsigned int c6x_silicon_rev;
  39. EXPORT_SYMBOL_GPL(c6x_silicon_rev);
  40. /*
  41. * Device status register. This holds information
  42. * about device configuration needed by some drivers.
  43. */
  44. unsigned int c6x_devstat;
  45. EXPORT_SYMBOL_GPL(c6x_devstat);
  46. /*
  47. * Some SoCs have fuse registers holding a unique MAC
  48. * address. This is parsed out of the device tree with
  49. * the resulting MAC being held here.
  50. */
  51. unsigned char c6x_fuse_mac[6];
  52. unsigned long memory_start;
  53. unsigned long memory_end;
  54. unsigned long ram_start;
  55. unsigned long ram_end;
  56. /* Uncached memory for DMA consistent use (memdma=) */
  57. static unsigned long dma_start __initdata;
  58. static unsigned long dma_size __initdata;
  59. char c6x_command_line[COMMAND_LINE_SIZE];
  60. #if defined(CONFIG_CMDLINE_BOOL)
  61. static const char default_command_line[COMMAND_LINE_SIZE] __section(.cmdline) =
  62. CONFIG_CMDLINE;
  63. #endif
  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. 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_devtree(fdt);
  246. /* parse_early_param needs a boot_command_line */
  247. strlcpy(boot_command_line, c6x_command_line, COMMAND_LINE_SIZE);
  248. parse_early_param();
  249. }
  250. void __init setup_arch(char **cmdline_p)
  251. {
  252. int bootmap_size;
  253. struct memblock_region *reg;
  254. printk(KERN_INFO "Initializing kernel\n");
  255. /* Initialize command line */
  256. *cmdline_p = c6x_command_line;
  257. memory_end = ram_end;
  258. memory_end &= ~(PAGE_SIZE - 1);
  259. if (mem_size && (PAGE_OFFSET + PAGE_ALIGN(mem_size)) < memory_end)
  260. memory_end = PAGE_OFFSET + PAGE_ALIGN(mem_size);
  261. /* add block that this kernel can use */
  262. memblock_add(PAGE_OFFSET, memory_end - PAGE_OFFSET);
  263. /* reserve kernel text/data/bss */
  264. memblock_reserve(PAGE_OFFSET,
  265. PAGE_ALIGN((unsigned long)&_end - PAGE_OFFSET));
  266. if (dma_size) {
  267. /* align to cacheability granularity */
  268. dma_size = CACHE_REGION_END(dma_size);
  269. if (!dma_start)
  270. dma_start = memory_end - dma_size;
  271. /* align to cacheability granularity */
  272. dma_start = CACHE_REGION_START(dma_start);
  273. /* reserve DMA memory taken from kernel memory */
  274. if (memblock_is_region_memory(dma_start, dma_size))
  275. memblock_reserve(dma_start, dma_size);
  276. }
  277. memory_start = PAGE_ALIGN((unsigned int) &_end);
  278. printk(KERN_INFO "Memory Start=%08lx, Memory End=%08lx\n",
  279. memory_start, memory_end);
  280. #ifdef CONFIG_BLK_DEV_INITRD
  281. /*
  282. * Reserve initrd memory if in kernel memory.
  283. */
  284. if (initrd_start < initrd_end)
  285. if (memblock_is_region_memory(initrd_start,
  286. initrd_end - initrd_start))
  287. memblock_reserve(initrd_start,
  288. initrd_end - initrd_start);
  289. #endif
  290. init_mm.start_code = (unsigned long) &_stext;
  291. init_mm.end_code = (unsigned long) &_etext;
  292. init_mm.end_data = memory_start;
  293. init_mm.brk = memory_start;
  294. /*
  295. * Give all the memory to the bootmap allocator, tell it to put the
  296. * boot mem_map at the start of memory
  297. */
  298. bootmap_size = init_bootmem_node(NODE_DATA(0),
  299. memory_start >> PAGE_SHIFT,
  300. PAGE_OFFSET >> PAGE_SHIFT,
  301. memory_end >> PAGE_SHIFT);
  302. memblock_reserve(memory_start, bootmap_size);
  303. unflatten_device_tree();
  304. c6x_cache_init();
  305. /* Set the whole external memory as non-cacheable */
  306. disable_caching(ram_start, ram_end - 1);
  307. /* Set caching of external RAM used by Linux */
  308. for_each_memblock(memory, reg)
  309. enable_caching(CACHE_REGION_START(reg->base),
  310. CACHE_REGION_START(reg->base + reg->size - 1));
  311. #ifdef CONFIG_BLK_DEV_INITRD
  312. /*
  313. * Enable caching for initrd which falls outside kernel memory.
  314. */
  315. if (initrd_start < initrd_end) {
  316. if (!memblock_is_region_memory(initrd_start,
  317. initrd_end - initrd_start))
  318. enable_caching(CACHE_REGION_START(initrd_start),
  319. CACHE_REGION_START(initrd_end - 1));
  320. }
  321. #endif
  322. /*
  323. * Disable caching for dma coherent memory taken from kernel memory.
  324. */
  325. if (dma_size && memblock_is_region_memory(dma_start, dma_size))
  326. disable_caching(dma_start,
  327. CACHE_REGION_START(dma_start + dma_size - 1));
  328. /* Initialize the coherent memory allocator */
  329. coherent_mem_init(dma_start, dma_size);
  330. /*
  331. * Free all memory as a starting point.
  332. */
  333. free_bootmem(PAGE_OFFSET, memory_end - PAGE_OFFSET);
  334. /*
  335. * Then reserve memory which is already being used.
  336. */
  337. for_each_memblock(reserved, reg) {
  338. pr_debug("reserved - 0x%08x-0x%08x\n",
  339. (u32) reg->base, (u32) reg->size);
  340. reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
  341. }
  342. max_low_pfn = PFN_DOWN(memory_end);
  343. min_low_pfn = PFN_UP(memory_start);
  344. max_mapnr = max_low_pfn - min_low_pfn;
  345. /* Get kmalloc into gear */
  346. paging_init();
  347. /*
  348. * Probe for Device State Configuration Registers.
  349. * We have to do this early in case timer needs to be enabled
  350. * through DSCR.
  351. */
  352. dscr_probe();
  353. /* We do this early for timer and core clock frequency */
  354. c64x_setup_clocks();
  355. /* Get CPU info */
  356. get_cpuinfo();
  357. #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
  358. conswitchp = &dummy_con;
  359. #endif
  360. }
  361. #define cpu_to_ptr(n) ((void *)((long)(n)+1))
  362. #define ptr_to_cpu(p) ((long)(p) - 1)
  363. static int show_cpuinfo(struct seq_file *m, void *v)
  364. {
  365. int n = ptr_to_cpu(v);
  366. struct cpuinfo_c6x *p = &per_cpu(cpu_data, n);
  367. if (n == 0) {
  368. seq_printf(m,
  369. "soc\t\t: %s\n"
  370. "soc revision\t: 0x%x\n"
  371. "soc cores\t: %d\n",
  372. c6x_soc_name, c6x_silicon_rev, c6x_num_cores);
  373. }
  374. seq_printf(m,
  375. "\n"
  376. "processor\t: %d\n"
  377. "cpu\t\t: %s\n"
  378. "core revision\t: %s\n"
  379. "core voltage\t: %s\n"
  380. "core id\t\t: %d\n"
  381. "mmu\t\t: %s\n"
  382. "fpu\t\t: %s\n"
  383. "cpu MHz\t\t: %u\n"
  384. "bogomips\t: %lu.%02lu\n\n",
  385. n,
  386. p->cpu_name, p->cpu_rev, p->cpu_voltage,
  387. p->core_id, p->mmu, p->fpu,
  388. (c6x_core_freq + 500000) / 1000000,
  389. (loops_per_jiffy/(500000/HZ)),
  390. (loops_per_jiffy/(5000/HZ))%100);
  391. return 0;
  392. }
  393. static void *c_start(struct seq_file *m, loff_t *pos)
  394. {
  395. return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
  396. }
  397. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  398. {
  399. ++*pos;
  400. return NULL;
  401. }
  402. static void c_stop(struct seq_file *m, void *v)
  403. {
  404. }
  405. const struct seq_operations cpuinfo_op = {
  406. c_start,
  407. c_stop,
  408. c_next,
  409. show_cpuinfo
  410. };
  411. static struct cpu cpu_devices[NR_CPUS];
  412. static int __init topology_init(void)
  413. {
  414. int i;
  415. for_each_present_cpu(i)
  416. register_cpu(&cpu_devices[i], i);
  417. return 0;
  418. }
  419. subsys_initcall(topology_init);