2 * Port on Texas Instruments TMS320C6x architecture
4 * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
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.
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>
31 #include <asm/sections.h>
32 #include <asm/div64.h>
33 #include <asm/setup.h>
35 #include <asm/clock.h>
37 #include <asm/special_insns.h>
39 static const char *c6x_soc_name;
42 EXPORT_SYMBOL_GPL(c6x_num_cores);
44 unsigned int c6x_silicon_rev;
45 EXPORT_SYMBOL_GPL(c6x_silicon_rev);
48 * Device status register. This holds information
49 * about device configuration needed by some drivers.
51 unsigned int c6x_devstat;
52 EXPORT_SYMBOL_GPL(c6x_devstat);
55 * Some SoCs have fuse registers holding a unique MAC
56 * address. This is parsed out of the device tree with
57 * the resulting MAC being held here.
59 unsigned char c6x_fuse_mac[6];
61 unsigned long memory_start;
62 unsigned long memory_end;
64 unsigned long ram_start;
65 unsigned long ram_end;
67 /* Uncached memory for DMA consistent use (memdma=) */
68 static unsigned long dma_start __initdata;
69 static unsigned long dma_size __initdata;
71 char c6x_command_line[COMMAND_LINE_SIZE];
73 #if defined(CONFIG_CMDLINE_BOOL)
74 static const char default_command_line[COMMAND_LINE_SIZE] __section(.cmdline) =
80 const char *cpu_voltage;
88 static DEFINE_PER_CPU(struct cpuinfo_c6x, cpu_data);
90 unsigned int ticks_per_ns_scaled;
91 EXPORT_SYMBOL(ticks_per_ns_scaled);
93 unsigned int c6x_core_freq;
95 static void __init get_cpuinfo(void)
97 unsigned cpu_id, rev_id, csr;
98 struct clk *coreclk = clk_get_sys(NULL, "core");
99 unsigned long core_khz;
101 struct cpuinfo_c6x *p;
102 struct device_node *node, *np;
104 p = &per_cpu(cpu_data, smp_processor_id());
106 if (!IS_ERR(coreclk))
107 c6x_core_freq = clk_get_rate(coreclk);
110 "Cannot find core clock frequency. Using 700MHz\n");
111 c6x_core_freq = 700000000;
114 core_khz = c6x_core_freq / 1000;
116 tmp = (uint64_t)core_khz << C6X_NDELAY_SCALE;
117 do_div(tmp, 1000000);
118 ticks_per_ns_scaled = tmp;
122 rev_id = (csr >> 16) & 0xff;
126 p->cpu_voltage = "unknown";
130 p->cpu_name = "C67x";
134 p->cpu_name = "C62x";
137 p->cpu_name = "C64x";
140 p->cpu_name = "C64x";
143 p->cpu_name = "C64x+";
144 p->cpu_voltage = "1.2";
147 p->cpu_name = "unknown";
155 p->cpu_rev = "DM640/DM641/DM642/DM643";
156 p->cpu_voltage = "1.2 - 1.4";
158 p->cpu_rev = "C6201";
159 p->cpu_voltage = "2.5";
163 p->cpu_rev = "C6201B/C6202/C6211";
164 p->cpu_voltage = "1.8";
167 p->cpu_rev = "C6202B/C6203/C6204/C6205";
168 p->cpu_voltage = "1.5";
171 p->cpu_rev = "C6701 revision 0 (early CPU)";
172 p->cpu_voltage = "1.8";
175 p->cpu_rev = "C6701/C6711/C6712";
176 p->cpu_voltage = "1.8";
180 p->cpu_voltage = "1.5";
183 p->cpu_rev = "unknown";
186 p->cpu_rev = p->__cpu_rev;
187 snprintf(p->__cpu_rev, sizeof(p->__cpu_rev), "0x%x", cpu_id);
190 p->core_id = get_coreid();
192 node = of_find_node_by_name(NULL, "cpus");
194 for_each_child_of_node(node, np)
195 if (!strcmp("cpu", np->name))
200 node = of_find_node_by_name(NULL, "soc");
202 if (of_property_read_string(node, "model", &c6x_soc_name))
203 c6x_soc_name = "unknown";
206 c6x_soc_name = "unknown";
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);
214 * Early parsing of the command line
216 static u32 mem_size __initdata;
218 /* "mem=" parsing. */
219 static int __init early_mem(char *p)
224 mem_size = memparse(p, &p);
225 /* don't remove all of memory when handling "mem={invalid}" */
231 early_param("mem", early_mem);
233 /* "memdma=<size>[@<address>]" parsing. */
234 static int __init early_memdma(char *p)
239 dma_size = memparse(p, &p);
241 dma_start = memparse(p, &p);
245 early_param("memdma", early_memdma);
247 int __init c6x_add_memory(phys_addr_t start, unsigned long size)
249 static int ram_found __initdata;
251 /* We only handle one bank (the one with PAGE_OFFSET) for now */
255 if (start > PAGE_OFFSET || PAGE_OFFSET >= (start + size))
259 ram_end = start + size;
266 * Do early machine setup and device tree parsing. This is called very
267 * early on the boot process.
269 notrace void __init machine_init(unsigned long dt_ptr)
271 struct boot_param_header *dtb = __va(dt_ptr);
272 struct boot_param_header *fdt = (struct boot_param_header *)_fdt_start;
274 /* interrupts must be masked */
278 * Set the Interrupt Service Table (IST) to the beginning of the
281 set_ist(_vectors_start);
286 * dtb is passed in from bootloader.
287 * fdt is linked in blob.
289 if (dtb && dtb != fdt)
292 /* Do some early initialization based on the flat device tree */
293 early_init_devtree(fdt);
295 /* parse_early_param needs a boot_command_line */
296 strlcpy(boot_command_line, c6x_command_line, COMMAND_LINE_SIZE);
300 void __init setup_arch(char **cmdline_p)
303 struct memblock_region *reg;
305 printk(KERN_INFO "Initializing kernel\n");
307 /* Initialize command line */
308 *cmdline_p = c6x_command_line;
310 memory_end = ram_end;
311 memory_end &= ~(PAGE_SIZE - 1);
313 if (mem_size && (PAGE_OFFSET + PAGE_ALIGN(mem_size)) < memory_end)
314 memory_end = PAGE_OFFSET + PAGE_ALIGN(mem_size);
316 /* add block that this kernel can use */
317 memblock_add(PAGE_OFFSET, memory_end - PAGE_OFFSET);
319 /* reserve kernel text/data/bss */
320 memblock_reserve(PAGE_OFFSET,
321 PAGE_ALIGN((unsigned long)&_end - PAGE_OFFSET));
324 /* align to cacheability granularity */
325 dma_size = CACHE_REGION_END(dma_size);
328 dma_start = memory_end - dma_size;
330 /* align to cacheability granularity */
331 dma_start = CACHE_REGION_START(dma_start);
333 /* reserve DMA memory taken from kernel memory */
334 if (memblock_is_region_memory(dma_start, dma_size))
335 memblock_reserve(dma_start, dma_size);
338 memory_start = PAGE_ALIGN((unsigned int) &_end);
340 printk(KERN_INFO "Memory Start=%08lx, Memory End=%08lx\n",
341 memory_start, memory_end);
343 #ifdef CONFIG_BLK_DEV_INITRD
345 * Reserve initrd memory if in kernel memory.
347 if (initrd_start < initrd_end)
348 if (memblock_is_region_memory(initrd_start,
349 initrd_end - initrd_start))
350 memblock_reserve(initrd_start,
351 initrd_end - initrd_start);
354 init_mm.start_code = (unsigned long) &_stext;
355 init_mm.end_code = (unsigned long) &_etext;
356 init_mm.end_data = memory_start;
357 init_mm.brk = memory_start;
360 * Give all the memory to the bootmap allocator, tell it to put the
361 * boot mem_map at the start of memory
363 bootmap_size = init_bootmem_node(NODE_DATA(0),
364 memory_start >> PAGE_SHIFT,
365 PAGE_OFFSET >> PAGE_SHIFT,
366 memory_end >> PAGE_SHIFT);
367 memblock_reserve(memory_start, bootmap_size);
369 unflatten_device_tree();
373 /* Set the whole external memory as non-cacheable */
374 disable_caching(ram_start, ram_end - 1);
376 /* Set caching of external RAM used by Linux */
377 for_each_memblock(memory, reg)
378 enable_caching(CACHE_REGION_START(reg->base),
379 CACHE_REGION_START(reg->base + reg->size - 1));
381 #ifdef CONFIG_BLK_DEV_INITRD
383 * Enable caching for initrd which falls outside kernel memory.
385 if (initrd_start < initrd_end) {
386 if (!memblock_is_region_memory(initrd_start,
387 initrd_end - initrd_start))
388 enable_caching(CACHE_REGION_START(initrd_start),
389 CACHE_REGION_START(initrd_end - 1));
394 * Disable caching for dma coherent memory taken from kernel memory.
396 if (dma_size && memblock_is_region_memory(dma_start, dma_size))
397 disable_caching(dma_start,
398 CACHE_REGION_START(dma_start + dma_size - 1));
400 /* Initialize the coherent memory allocator */
401 coherent_mem_init(dma_start, dma_size);
404 * Free all memory as a starting point.
406 free_bootmem(PAGE_OFFSET, memory_end - PAGE_OFFSET);
409 * Then reserve memory which is already being used.
411 for_each_memblock(reserved, reg) {
412 pr_debug("reserved - 0x%08x-0x%08x\n",
413 (u32) reg->base, (u32) reg->size);
414 reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
417 max_low_pfn = PFN_DOWN(memory_end);
418 min_low_pfn = PFN_UP(memory_start);
419 max_mapnr = max_low_pfn - min_low_pfn;
421 /* Get kmalloc into gear */
425 * Probe for Device State Configuration Registers.
426 * We have to do this early in case timer needs to be enabled
431 /* We do this early for timer and core clock frequency */
437 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
438 conswitchp = &dummy_con;
442 #define cpu_to_ptr(n) ((void *)((long)(n)+1))
443 #define ptr_to_cpu(p) ((long)(p) - 1)
445 static int show_cpuinfo(struct seq_file *m, void *v)
447 int n = ptr_to_cpu(v);
448 struct cpuinfo_c6x *p = &per_cpu(cpu_data, n);
453 "soc revision\t: 0x%x\n"
455 c6x_soc_name, c6x_silicon_rev, c6x_num_cores);
462 "core revision\t: %s\n"
463 "core voltage\t: %s\n"
468 "bogomips\t: %lu.%02lu\n\n",
470 p->cpu_name, p->cpu_rev, p->cpu_voltage,
471 p->core_id, p->mmu, p->fpu,
472 (c6x_core_freq + 500000) / 1000000,
473 (loops_per_jiffy/(500000/HZ)),
474 (loops_per_jiffy/(5000/HZ))%100);
479 static void *c_start(struct seq_file *m, loff_t *pos)
481 return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
483 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
488 static void c_stop(struct seq_file *m, void *v)
492 const struct seq_operations cpuinfo_op = {
499 static struct cpu cpu_devices[NR_CPUS];
501 static int __init topology_init(void)
505 for_each_present_cpu(i)
506 register_cpu(&cpu_devices[i], i);
511 subsys_initcall(topology_init);