aboutsummaryrefslogtreecommitdiffstats
path: root/arch/hexagon/kernel
diff options
context:
space:
mode:
authorRichard Kuo <rkuo@codeaurora.org>2011-10-31 19:42:28 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-11-01 10:34:19 -0400
commite03167b26b7fcffea11e82f5672472a23a88ffbc (patch)
treefe0e156ad25c26944ae338447f7eb04fb16fc0ea /arch/hexagon/kernel
parent4b30f9652ef0080ca351109220ca5bd617749365 (diff)
Hexagon: Add startup code
Signed-off-by: Richard Kuo <rkuo@codeaurora.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/hexagon/kernel')
-rw-r--r--arch/hexagon/kernel/head.S162
-rw-r--r--arch/hexagon/kernel/reset.c38
-rw-r--r--arch/hexagon/kernel/setup.c145
3 files changed, 345 insertions, 0 deletions
diff --git a/arch/hexagon/kernel/head.S b/arch/hexagon/kernel/head.S
new file mode 100644
index 000000000000..8e6b819125a3
--- /dev/null
+++ b/arch/hexagon/kernel/head.S
@@ -0,0 +1,162 @@
1/*
2 * Early kernel startup code for Hexagon
3 *
4 * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
5 *
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 and
9 * only version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301, USA.
20 */
21
22#include <linux/linkage.h>
23#include <linux/init.h>
24#include <asm/asm-offsets.h>
25#include <asm/mem-layout.h>
26#include <asm/vm_mmu.h>
27#include <asm/page.h>
28
29 __INIT
30ENTRY(stext)
31 /*
32 * VMM will already have set up true vector page, MMU, etc.
33 * To set up initial kernel identity map, we have to pass
34 * the VMM a pointer to some canonical page tables. In
35 * this implementation, we're assuming that we've got
36 * them precompiled. Generate value in R24, as we'll need
37 * it again shortly.
38 */
39 r24.L = #LO(swapper_pg_dir)
40 r24.H = #HI(swapper_pg_dir)
41
42 /*
43 * Symbol is kernel segment address, but we need
44 * the logical/physical address.
45 */
46 r24 = asl(r24, #2)
47 r24 = lsr(r24, #2)
48
49 r0 = r24
50
51 /*
52 * Initialize a 16MB PTE to make the virtual and physical
53 * addresses where the kernel was loaded be identical.
54 */
55#define PTE_BITS ( __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X \
56 | __HEXAGON_C_WB_L2 << 6 \
57 | __HVM_PDE_S_4MB)
58
59 r1 = pc
60 r2.H = #0xffc0
61 r2.L = #0x0000
62 r1 = and(r1,r2) /* round PC to 4MB boundary */
63 r2 = lsr(r1, #22) /* 4MB page number */
64 r2 = asl(r2, #2) /* times sizeof(PTE) (4bytes) */
65 r0 = add(r0,r2) /* r0 = address of correct PTE */
66 r2 = #PTE_BITS
67 r1 = add(r1,r2) /* r1 = 4MB PTE for the first entry */
68 r2.h = #0x0040
69 r2.l = #0x0000 /* 4MB */
70 memw(r0 ++ #4) = r1
71 r1 = add(r1, r2)
72 memw(r0 ++ #4) = r1
73
74 r0 = r24
75
76 /*
77 * The subroutine wrapper around the virtual instruction touches
78 * no memory, so we should be able to use it even here.
79 */
80 call __vmnewmap;
81
82 /* Jump into virtual address range. */
83
84 r31.h = #hi(__head_s_vaddr_target)
85 r31.l = #lo(__head_s_vaddr_target)
86 jumpr r31
87
88 /* Insert trippy space effects. */
89
90__head_s_vaddr_target:
91 /*
92 * Tear down VA=PA translation now that we are running
93 * in the desgnated kernel segments.
94 */
95 r0 = #__HVM_PDE_S_INVALID
96 r1 = r24
97 loop0(1f,#0x100)
981:
99 {
100 memw(R1 ++ #4) = R0
101 }:endloop0
102
103 r0 = r24
104 call __vmnewmap
105
106 /* Go ahead and install the trap0 return so angel calls work */
107 r0.h = #hi(_K_provisional_vec)
108 r0.l = #lo(_K_provisional_vec)
109 call __vmsetvec
110
111 /*
112 * OK, at this point we should start to be much more careful,
113 * we're going to enter C code and start touching memory
114 * in all sorts of places.
115 * This means:
116 * SGP needs to be OK
117 * Need to lock shared resources
118 * A bunch of other things that will cause
119 * all kinds of painful bugs
120 */
121
122 /*
123 * Stack pointer should be pointed at the init task's
124 * thread stack, which should have been declared in arch/init_task.c.
125 * So uhhhhh...
126 * It's accessible via the init_thread_union, which is a union
127 * of a thread_info struct and a stack; of course, the top
128 * of the stack is not for you. The end of the stack
129 * is simply init_thread_union + THREAD_SIZE.
130 */
131
132 {r29.H = #HI(init_thread_union); r0.H = #HI(_THREAD_SIZE); }
133 {r29.L = #LO(init_thread_union); r0.L = #LO(_THREAD_SIZE); }
134
135 /* initialize the register used to point to current_thread_info */
136 /* Fixme: THREADINFO_REG can't be R2 because of that memset thing. */
137 {r29 = add(r29,r0); THREADINFO_REG = r29; }
138
139 /* Hack: zero bss; */
140 { r0.L = #LO(__bss_start); r1 = #0; r2.l = #LO(__bss_stop); }
141 { r0.H = #HI(__bss_start); r2.h = #HI(__bss_stop); }
142
143 r2 = sub(r2,r0);
144 call memset;
145
146 /* Time to make the doughnuts. */
147 call start_kernel
148
149 /*
150 * Should not reach here.
151 */
1521:
153 jump 1b
154
155.p2align PAGE_SHIFT
156ENTRY(external_cmdline_buffer)
157 .fill _PAGE_SIZE,1,0
158
159.data
160.p2align PAGE_SHIFT
161ENTRY(empty_zero_page)
162 .fill _PAGE_SIZE,1,0
diff --git a/arch/hexagon/kernel/reset.c b/arch/hexagon/kernel/reset.c
new file mode 100644
index 000000000000..4d72fc58e9b1
--- /dev/null
+++ b/arch/hexagon/kernel/reset.c
@@ -0,0 +1,38 @@
1/*
2 * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
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 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301, USA.
17 */
18
19#include <linux/smp.h>
20#include <asm/hexagon_vm.h>
21
22void machine_power_off(void)
23{
24 smp_send_stop();
25 __vmstop();
26}
27
28void machine_halt(void)
29{
30}
31
32void machine_restart(char *cmd)
33{
34}
35
36void pm_power_off(void)
37{
38}
diff --git a/arch/hexagon/kernel/setup.c b/arch/hexagon/kernel/setup.c
new file mode 100644
index 000000000000..1202f78d25cb
--- /dev/null
+++ b/arch/hexagon/kernel/setup.c
@@ -0,0 +1,145 @@
1/*
2 * Arch related setup for Hexagon
3 *
4 * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and
8 * only version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA.
19 */
20
21#include <linux/init.h>
22#include <linux/bootmem.h>
23#include <linux/mmzone.h>
24#include <linux/mm.h>
25#include <linux/seq_file.h>
26#include <linux/console.h>
27#include <linux/of_fdt.h>
28#include <asm/io.h>
29#include <asm/sections.h>
30#include <asm/setup.h>
31#include <asm/processor.h>
32#include <asm/hexagon_vm.h>
33#include <asm/vm_mmu.h>
34#include <asm/time.h>
35#ifdef CONFIG_OF
36#include <asm/prom.h>
37#endif
38
39char cmd_line[COMMAND_LINE_SIZE];
40static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
41
42int on_simulator;
43
44void __cpuinit calibrate_delay(void)
45{
46 loops_per_jiffy = thread_freq_mhz * 1000000 / HZ;
47}
48
49/*
50 * setup_arch - high level architectural setup routine
51 * @cmdline_p: pointer to pointer to command-line arguments
52 */
53
54void __init setup_arch(char **cmdline_p)
55{
56 char *p = &external_cmdline_buffer;
57
58 /*
59 * These will eventually be pulled in via either some hypervisor
60 * or devicetree description. Hardwiring for now.
61 */
62 pcycle_freq_mhz = 600;
63 thread_freq_mhz = 100;
64 sleep_clk_freq = 32000;
65
66 /*
67 * Set up event bindings to handle exceptions and interrupts.
68 */
69 __vmsetvec(_K_VM_event_vector);
70
71 /*
72 * Simulator has a few differences from the hardware.
73 * For now, check uninitialized-but-mapped memory
74 * prior to invoking setup_arch_memory().
75 */
76 if (*(int *)((unsigned long)_end + 8) == 0x1f1f1f1f)
77 on_simulator = 1;
78 else
79 on_simulator = 0;
80
81 if (p[0] != '\0')
82 strlcpy(boot_command_line, p, COMMAND_LINE_SIZE);
83 else
84 strlcpy(boot_command_line, default_command_line,
85 COMMAND_LINE_SIZE);
86
87 /*
88 * boot_command_line and the value set up by setup_arch
89 * are both picked up by the init code. If no reason to
90 * make them different, pass the same pointer back.
91 */
92 strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
93 *cmdline_p = cmd_line;
94
95 parse_early_param();
96
97 setup_arch_memory();
98
99#ifdef CONFIG_SMP
100 smp_start_cpus();
101#endif
102}
103
104/*
105 * Functions for dumping CPU info via /proc
106 * Probably should move to kernel/proc.c or something.
107 */
108static void *c_start(struct seq_file *m, loff_t *pos)
109{
110 return *pos < nr_cpu_ids ? (void *)((unsigned long) *pos + 1) : NULL;
111}
112
113static void *c_next(struct seq_file *m, void *v, loff_t *pos)
114{
115 ++*pos;
116 return c_start(m, pos);
117}
118
119static void c_stop(struct seq_file *m, void *v)
120{
121}
122
123/*
124 * Eventually this will dump information about
125 * CPU properties like ISA level, TLB size, etc.
126 */
127static int show_cpuinfo(struct seq_file *m, void *v)
128{
129 int cpu = (unsigned long) v - 1;
130
131 seq_printf(m, "processor\t: %d\n", cpu);
132 seq_printf(m, "model name\t: Hexagon Virtual Machine\n");
133 seq_printf(m, "BogoMips\t: %lu.%02lu\n",
134 (loops_per_jiffy * HZ) / 500000,
135 ((loops_per_jiffy * HZ) / 5000) % 100);
136 seq_printf(m, "\n");
137 return 0;
138}
139
140const struct seq_operations cpuinfo_op = {
141 .start = &c_start,
142 .next = &c_next,
143 .stop = &c_stop,
144 .show = &show_cpuinfo,
145};