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