blob: 6e3996cb9df9ebc47dcc8225a4ddfa8bddabc03f [file] [log] [blame]
Vineet Guptac121c502013-01-18 15:12:20 +05301/*
2 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/seq_file.h>
10#include <linux/fs.h>
11#include <linux/delay.h>
12#include <linux/root_dev.h>
13#include <linux/console.h>
14#include <linux/module.h>
15#include <linux/cpu.h>
Vineet Gupta999159a2013-01-22 17:00:52 +053016#include <linux/of_fdt.h>
17#include <asm/sections.h>
Vineet Guptac121c502013-01-18 15:12:20 +053018#include <asm/arcregs.h>
19#include <asm/tlb.h>
20#include <asm/cache.h>
21#include <asm/setup.h>
22#include <asm/page.h>
23#include <asm/irq.h>
24#include <asm/arcregs.h>
Vineet Gupta999159a2013-01-22 17:00:52 +053025#include <asm/prom.h>
Vineet Gupta854a0d92013-01-22 17:03:19 +053026#include <asm/unwind.h>
Vineet Guptac121c502013-01-18 15:12:20 +053027
28#define FIX_PTR(x) __asm__ __volatile__(";" : "+r"(x))
29
30int running_on_hw = 1; /* vs. on ISS */
31
32char __initdata command_line[COMMAND_LINE_SIZE];
33
34struct task_struct *_current_task[NR_CPUS]; /* For stack switching */
35
36struct cpuinfo_arc cpuinfo_arc700[NR_CPUS];
37
38void __init read_arc_build_cfg_regs(void)
39{
40 read_decode_mmu_bcr();
41 read_decode_cache_bcr();
42}
43
44/*
45 * Initialize and setup the processor core
46 * This is called by all the CPUs thus should not do special case stuff
47 * such as only for boot CPU etc
48 */
49
50void __init setup_processor(void)
51{
52 read_arc_build_cfg_regs();
53 arc_init_IRQ();
54 arc_mmu_init();
55 arc_cache_init();
56}
57
58void __init __attribute__((weak)) arc_platform_early_init(void)
59{
60}
61
62void __init setup_arch(char **cmdline_p)
63{
Vineet Gupta999159a2013-01-22 17:00:52 +053064 int rc;
65
Vineet Guptac121c502013-01-18 15:12:20 +053066#ifdef CONFIG_CMDLINE_UBOOT
67 /* Make sure that a whitespace is inserted before */
68 strlcat(command_line, " ", sizeof(command_line));
69#endif
70 /*
71 * Append .config cmdline to base command line, which might already
72 * contain u-boot "bootargs" (handled by head.S, if so configured)
73 */
74 strlcat(command_line, CONFIG_CMDLINE, sizeof(command_line));
75
76 /* Save unparsed command line copy for /proc/cmdline */
77 strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
78 *cmdline_p = command_line;
79
Vineet Gupta999159a2013-01-22 17:00:52 +053080 rc = setup_machine_fdt(__dtb_start);
81
Vineet Guptac121c502013-01-18 15:12:20 +053082 /* To force early parsing of things like mem=xxx */
83 parse_early_param();
84
85 /* Platform/board specific: e.g. early console registration */
86 arc_platform_early_init();
87
88 setup_processor();
89
Vineet Gupta41195d22013-01-18 15:12:23 +053090#ifdef CONFIG_SMP
91 smp_init_cpus();
92#endif
93
Vineet Guptac121c502013-01-18 15:12:20 +053094 setup_arch_memory();
95
Vineet Gupta999159a2013-01-22 17:00:52 +053096 unflatten_device_tree();
97
Vineet Guptac121c502013-01-18 15:12:20 +053098 /* Can be issue if someone passes cmd line arg "ro"
99 * But that is unlikely so keeping it as it is
100 */
101 root_mountflags &= ~MS_RDONLY;
102
103 console_verbose();
104
105#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
106 conswitchp = &dummy_con;
107#endif
108
Vineet Gupta854a0d92013-01-22 17:03:19 +0530109 arc_unwind_init();
110 arc_unwind_setup();
Vineet Guptac121c502013-01-18 15:12:20 +0530111}
112
113/*
114 * Get CPU information for use by the procfs.
115 */
116
117#define cpu_to_ptr(c) ((void *)(0xFFFF0000 | (unsigned int)(c)))
118#define ptr_to_cpu(p) (~0xFFFF0000UL & (unsigned int)(p))
119
120static int show_cpuinfo(struct seq_file *m, void *v)
121{
122 char *str;
123 int cpu_id = ptr_to_cpu(v);
124
125 str = (char *)__get_free_page(GFP_TEMPORARY);
126 if (!str)
127 goto done;
128
129 seq_printf(m, "ARC700 #%d\n", cpu_id);
130
131 seq_printf(m, "Bogo MIPS : \t%lu.%02lu\n",
132 loops_per_jiffy / (500000 / HZ),
133 (loops_per_jiffy / (5000 / HZ)) % 100);
134
135 free_page((unsigned long)str);
136done:
137 seq_printf(m, "\n\n");
138
139 return 0;
140}
141
142static void *c_start(struct seq_file *m, loff_t *pos)
143{
144 /*
145 * Callback returns cpu-id to iterator for show routine, NULL to stop.
146 * However since NULL is also a valid cpu-id (0), we use a round-about
147 * way to pass it w/o having to kmalloc/free a 2 byte string.
148 * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
149 */
150 return *pos < num_possible_cpus() ? cpu_to_ptr(*pos) : NULL;
151}
152
153static void *c_next(struct seq_file *m, void *v, loff_t *pos)
154{
155 ++*pos;
156 return c_start(m, pos);
157}
158
159static void c_stop(struct seq_file *m, void *v)
160{
161}
162
163const struct seq_operations cpuinfo_op = {
164 .start = c_start,
165 .next = c_next,
166 .stop = c_stop,
167 .show = show_cpuinfo
168};
169
170static DEFINE_PER_CPU(struct cpu, cpu_topology);
171
172static int __init topology_init(void)
173{
174 int cpu;
175
176 for_each_present_cpu(cpu)
177 register_cpu(&per_cpu(cpu_topology, cpu), cpu);
178
179 return 0;
180}
181
182subsys_initcall(topology_init);