Loading...
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * TILE startup code.
15 */
16
17#include <linux/linkage.h>
18#include <linux/init.h>
19#include <asm/page.h>
20#include <asm/pgtable.h>
21#include <asm/thread_info.h>
22#include <asm/processor.h>
23#include <asm/asm-offsets.h>
24#include <hv/hypervisor.h>
25#include <arch/chip.h>
26#include <arch/spr_def.h>
27
28/*
29 * This module contains the entry code for kernel images. It performs the
30 * minimal setup needed to call the generic C routines.
31 */
32
33 __HEAD
34ENTRY(_start)
35 /* Notify the hypervisor of what version of the API we want */
36 {
37 movei r1, TILE_CHIP
38 movei r2, TILE_CHIP_REV
39 }
40 {
41 moveli r0, _HV_VERSION
42 jal hv_init
43 }
44 /* Get a reasonable default ASID in r0 */
45 {
46 move r0, zero
47 jal hv_inquire_asid
48 }
49
50 /*
51 * Install the default page table. The relocation required to
52 * statically define the table is a bit too complex, so we have
53 * to plug in the pointer from the L0 to the L1 table by hand.
54 * We only do this on the first cpu to boot, though, since the
55 * other CPUs should see a properly-constructed page table.
56 */
57 {
58 v4int_l r2, zero, r0 /* ASID for hv_install_context */
59 moveli r4, hw1_last(swapper_pgprot - PAGE_OFFSET)
60 }
61 {
62 shl16insli r4, r4, hw0(swapper_pgprot - PAGE_OFFSET)
63 }
64 {
65 ld r1, r4 /* access_pte for hv_install_context */
66 }
67 {
68 moveli r0, hw1_last(.Lsv_data_pmd - PAGE_OFFSET)
69 moveli r6, hw1_last(temp_data_pmd - PAGE_OFFSET)
70 }
71 {
72 /* After initializing swapper_pgprot, HV_PTE_GLOBAL is set. */
73 bfextu r7, r1, HV_PTE_INDEX_GLOBAL, HV_PTE_INDEX_GLOBAL
74 inv r4
75 }
76 bnez r7, .Lno_write
77 {
78 shl16insli r0, r0, hw0(.Lsv_data_pmd - PAGE_OFFSET)
79 shl16insli r6, r6, hw0(temp_data_pmd - PAGE_OFFSET)
80 }
81 {
82 /* Cut off the low bits of the PT address. */
83 shrui r6, r6, HV_LOG2_PAGE_TABLE_ALIGN
84 /* Start with our access pte. */
85 move r5, r1
86 }
87 {
88 /* Stuff the address into the page table pointer slot of the PTE. */
89 bfins r5, r6, HV_PTE_INDEX_PTFN, \
90 HV_PTE_INDEX_PTFN + HV_PTE_PTFN_BITS - 1
91 }
92 {
93 /* Store the L0 data PTE. */
94 st r0, r5
95 addli r6, r6, (temp_code_pmd - temp_data_pmd) >> \
96 HV_LOG2_PAGE_TABLE_ALIGN
97 }
98 {
99 addli r0, r0, .Lsv_code_pmd - .Lsv_data_pmd
100 bfins r5, r6, HV_PTE_INDEX_PTFN, \
101 HV_PTE_INDEX_PTFN + HV_PTE_PTFN_BITS - 1
102 }
103 /* Store the L0 code PTE. */
104 st r0, r5
105
106.Lno_write:
107 moveli lr, hw2_last(1f)
108 {
109 shl16insli lr, lr, hw1(1f)
110 moveli r0, hw1_last(swapper_pg_dir - PAGE_OFFSET)
111 }
112 {
113 shl16insli lr, lr, hw0(1f)
114 shl16insli r0, r0, hw0(swapper_pg_dir - PAGE_OFFSET)
115 }
116 {
117 moveli r3, CTX_PAGE_FLAG
118 j hv_install_context
119 }
1201:
121
122 /* Install the interrupt base. */
123 moveli r0, hw2_last(MEM_SV_START)
124 shl16insli r0, r0, hw1(MEM_SV_START)
125 shl16insli r0, r0, hw0(MEM_SV_START)
126 mtspr SPR_INTERRUPT_VECTOR_BASE_K, r0
127
128 /*
129 * Get our processor number and save it away in SAVE_K_0.
130 * Extract stuff from the topology structure: r4 = y, r6 = x,
131 * r5 = width. FIXME: consider whether we want to just make these
132 * 64-bit values (and if so fix smp_topology write below, too).
133 */
134 jal hv_inquire_topology
135 {
136 v4int_l r5, zero, r1 /* r5 = width */
137 shrui r4, r0, 32 /* r4 = y */
138 }
139 {
140 v4int_l r6, zero, r0 /* r6 = x */
141 mul_lu_lu r4, r4, r5
142 }
143 {
144 add r4, r4, r6 /* r4 == cpu == y*width + x */
145 }
146
147#ifdef CONFIG_SMP
148 /*
149 * Load up our per-cpu offset. When the first (master) tile
150 * boots, this value is still zero, so we will load boot_pc
151 * with start_kernel, and boot_sp with init_stack + THREAD_SIZE.
152 * The master tile initializes the per-cpu offset array, so that
153 * when subsequent (secondary) tiles boot, they will instead load
154 * from their per-cpu versions of boot_sp and boot_pc.
155 */
156 moveli r5, hw2_last(__per_cpu_offset)
157 shl16insli r5, r5, hw1(__per_cpu_offset)
158 shl16insli r5, r5, hw0(__per_cpu_offset)
159 shl3add r5, r4, r5
160 ld r5, r5
161 bnez r5, 1f
162
163 /*
164 * Save the width and height to the smp_topology variable
165 * for later use.
166 */
167 moveli r0, hw2_last(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
168 shl16insli r0, r0, hw1(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
169 shl16insli r0, r0, hw0(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
170 st r0, r1
1711:
172#else
173 move r5, zero
174#endif
175
176 /* Load and go with the correct pc and sp. */
177 {
178 moveli r1, hw2_last(boot_sp)
179 moveli r0, hw2_last(boot_pc)
180 }
181 {
182 shl16insli r1, r1, hw1(boot_sp)
183 shl16insli r0, r0, hw1(boot_pc)
184 }
185 {
186 shl16insli r1, r1, hw0(boot_sp)
187 shl16insli r0, r0, hw0(boot_pc)
188 }
189 {
190 add r1, r1, r5
191 add r0, r0, r5
192 }
193 ld r0, r0
194 ld sp, r1
195 or r4, sp, r4
196 mtspr SPR_SYSTEM_SAVE_K_0, r4 /* save ksp0 + cpu */
197 addi sp, sp, -STACK_TOP_DELTA
198 {
199 move lr, zero /* stop backtraces in the called function */
200 jr r0
201 }
202 ENDPROC(_start)
203
204__PAGE_ALIGNED_BSS
205 .align PAGE_SIZE
206ENTRY(empty_zero_page)
207 .fill PAGE_SIZE,1,0
208 END(empty_zero_page)
209
210 .macro PTE cpa, bits1
211 .quad HV_PTE_PAGE | HV_PTE_DIRTY | HV_PTE_PRESENT | HV_PTE_ACCESSED |\
212 HV_PTE_GLOBAL | (HV_PTE_MODE_CACHE_NO_L3 << HV_PTE_INDEX_MODE) |\
213 (\bits1) | (HV_CPA_TO_PTFN(\cpa) << HV_PTE_INDEX_PTFN)
214 .endm
215
216__PAGE_ALIGNED_DATA
217 .align PAGE_SIZE
218ENTRY(swapper_pg_dir)
219 .org swapper_pg_dir + PGD_INDEX(PAGE_OFFSET) * HV_PTE_SIZE
220.Lsv_data_pmd:
221 .quad 0 /* PTE temp_data_pmd - PAGE_OFFSET, 0 */
222 .org swapper_pg_dir + PGD_INDEX(MEM_SV_START) * HV_PTE_SIZE
223.Lsv_code_pmd:
224 .quad 0 /* PTE temp_code_pmd - PAGE_OFFSET, 0 */
225 .org swapper_pg_dir + SIZEOF_PGD
226 END(swapper_pg_dir)
227
228 .align HV_PAGE_TABLE_ALIGN
229ENTRY(temp_data_pmd)
230 /*
231 * We fill the PAGE_OFFSET pmd with huge pages with
232 * VA = PA + PAGE_OFFSET. We remap things with more precise access
233 * permissions later.
234 */
235 .set addr, 0
236 .rept PTRS_PER_PMD
237 PTE addr, HV_PTE_READABLE | HV_PTE_WRITABLE
238 .set addr, addr + HPAGE_SIZE
239 .endr
240 .org temp_data_pmd + SIZEOF_PMD
241 END(temp_data_pmd)
242
243 .align HV_PAGE_TABLE_ALIGN
244ENTRY(temp_code_pmd)
245 /*
246 * We fill the MEM_SV_START pmd with huge pages with
247 * VA = PA + PAGE_OFFSET. We remap things with more precise access
248 * permissions later.
249 */
250 .set addr, 0
251 .rept PTRS_PER_PMD
252 PTE addr, HV_PTE_READABLE | HV_PTE_EXECUTABLE
253 .set addr, addr + HPAGE_SIZE
254 .endr
255 .org temp_code_pmd + SIZEOF_PMD
256 END(temp_code_pmd)
257
258 /*
259 * Isolate swapper_pgprot to its own cache line, since each cpu
260 * starting up will read it using VA-is-PA and local homing.
261 * This would otherwise likely conflict with other data on the cache
262 * line, once we have set its permanent home in the page tables.
263 */
264 __INITDATA
265 .align CHIP_L2_LINE_SIZE()
266ENTRY(swapper_pgprot)
267 .quad HV_PTE_PRESENT | (HV_PTE_MODE_CACHE_NO_L3 << HV_PTE_INDEX_MODE)
268 .align CHIP_L2_LINE_SIZE()
269 END(swapper_pgprot)
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * TILE startup code.
15 */
16
17#include <linux/linkage.h>
18#include <linux/init.h>
19#include <asm/page.h>
20#include <asm/pgtable.h>
21#include <asm/thread_info.h>
22#include <asm/processor.h>
23#include <asm/asm-offsets.h>
24#include <hv/hypervisor.h>
25#include <arch/chip.h>
26#include <arch/spr_def.h>
27
28/* Extract two 32-bit bit values that were read into one register. */
29#ifdef __BIG_ENDIAN__
30#define GET_FIRST_INT(rd, rs) shrsi rd, rs, 32
31#define GET_SECOND_INT(rd, rs) addxi rd, rs, 0
32#else
33#define GET_FIRST_INT(rd, rs) addxi rd, rs, 0
34#define GET_SECOND_INT(rd, rs) shrsi rd, rs, 32
35#endif
36
37/*
38 * This module contains the entry code for kernel images. It performs the
39 * minimal setup needed to call the generic C routines.
40 */
41
42 __HEAD
43ENTRY(_start)
44 /* Notify the hypervisor of what version of the API we want */
45 {
46#if KERNEL_PL == 1 && _HV_VERSION == 13
47 /* Support older hypervisors by asking for API version 12. */
48 movei r0, _HV_VERSION_OLD_HV_INIT
49#else
50 movei r0, _HV_VERSION
51#endif
52 movei r1, TILE_CHIP
53 }
54 {
55 movei r2, TILE_CHIP_REV
56 movei r3, KERNEL_PL
57 }
58 jal _hv_init
59 /* Get a reasonable default ASID in r0 */
60 {
61 move r0, zero
62 jal _hv_inquire_asid
63 }
64
65 /*
66 * Install the default page table. The relocation required to
67 * statically define the table is a bit too complex, so we have
68 * to plug in the pointer from the L0 to the L1 table by hand.
69 * We only do this on the first cpu to boot, though, since the
70 * other CPUs should see a properly-constructed page table.
71 */
72 {
73 GET_FIRST_INT(r2, r0) /* ASID for hv_install_context */
74 moveli r4, hw1_last(swapper_pgprot - PAGE_OFFSET)
75 }
76 {
77 shl16insli r4, r4, hw0(swapper_pgprot - PAGE_OFFSET)
78 }
79 {
80 ld r1, r4 /* access_pte for hv_install_context */
81 }
82 {
83 moveli r0, hw1_last(.Lsv_data_pmd - PAGE_OFFSET)
84 moveli r6, hw1_last(temp_data_pmd - PAGE_OFFSET)
85 }
86 {
87 /* After initializing swapper_pgprot, HV_PTE_GLOBAL is set. */
88 bfextu r7, r1, HV_PTE_INDEX_GLOBAL, HV_PTE_INDEX_GLOBAL
89 finv r4
90 }
91 bnez r7, .Lno_write
92 {
93 shl16insli r0, r0, hw0(.Lsv_data_pmd - PAGE_OFFSET)
94 shl16insli r6, r6, hw0(temp_data_pmd - PAGE_OFFSET)
95 }
96 {
97 /* Cut off the low bits of the PT address. */
98 shrui r6, r6, HV_LOG2_PAGE_TABLE_ALIGN
99 /* Start with our access pte. */
100 move r5, r1
101 }
102 {
103 /* Stuff the address into the page table pointer slot of the PTE. */
104 bfins r5, r6, HV_PTE_INDEX_PTFN, \
105 HV_PTE_INDEX_PTFN + HV_PTE_PTFN_BITS - 1
106 }
107 {
108 /* Store the L0 data PTE. */
109 st r0, r5
110 addli r6, r6, (temp_code_pmd - temp_data_pmd) >> \
111 HV_LOG2_PAGE_TABLE_ALIGN
112 }
113 {
114 addli r0, r0, .Lsv_code_pmd - .Lsv_data_pmd
115 bfins r5, r6, HV_PTE_INDEX_PTFN, \
116 HV_PTE_INDEX_PTFN + HV_PTE_PTFN_BITS - 1
117 }
118 /* Store the L0 code PTE. */
119 st r0, r5
120
121.Lno_write:
122 moveli lr, hw2_last(1f)
123 {
124 shl16insli lr, lr, hw1(1f)
125 moveli r0, hw1_last(swapper_pg_dir - PAGE_OFFSET)
126 }
127 {
128 shl16insli lr, lr, hw0(1f)
129 shl16insli r0, r0, hw0(swapper_pg_dir - PAGE_OFFSET)
130 }
131 {
132 moveli r3, CTX_PAGE_FLAG
133 j _hv_install_context
134 }
1351:
136
137 /* Install the interrupt base. */
138 moveli r0, hw2_last(intrpt_start)
139 shl16insli r0, r0, hw1(intrpt_start)
140 shl16insli r0, r0, hw0(intrpt_start)
141 mtspr SPR_INTERRUPT_VECTOR_BASE_K, r0
142
143 /* Get our processor number and save it away in SAVE_K_0. */
144 jal _hv_inquire_topology
145 {
146 GET_FIRST_INT(r5, r1) /* r5 = width */
147 GET_SECOND_INT(r4, r0) /* r4 = y */
148 }
149 {
150 GET_FIRST_INT(r6, r0) /* r6 = x */
151 mul_lu_lu r4, r4, r5
152 }
153 {
154 add r4, r4, r6 /* r4 == cpu == y*width + x */
155 }
156
157#ifdef CONFIG_SMP
158 /*
159 * Load up our per-cpu offset. When the first (master) tile
160 * boots, this value is still zero, so we will load boot_pc
161 * with start_kernel, and boot_sp with at the top of init_stack.
162 * The master tile initializes the per-cpu offset array, so that
163 * when subsequent (secondary) tiles boot, they will instead load
164 * from their per-cpu versions of boot_sp and boot_pc.
165 */
166 moveli r5, hw2_last(__per_cpu_offset)
167 shl16insli r5, r5, hw1(__per_cpu_offset)
168 shl16insli r5, r5, hw0(__per_cpu_offset)
169 shl3add r5, r4, r5
170 ld r5, r5
171 bnez r5, 1f
172
173 /*
174 * Save the width and height to the smp_topology variable
175 * for later use.
176 */
177 moveli r0, hw2_last(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
178 shl16insli r0, r0, hw1(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
179 shl16insli r0, r0, hw0(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
180 st r0, r1
1811:
182#else
183 move r5, zero
184#endif
185
186 /* Load and go with the correct pc and sp. */
187 {
188 moveli r1, hw2_last(boot_sp)
189 moveli r0, hw2_last(boot_pc)
190 }
191 {
192 shl16insli r1, r1, hw1(boot_sp)
193 shl16insli r0, r0, hw1(boot_pc)
194 }
195 {
196 shl16insli r1, r1, hw0(boot_sp)
197 shl16insli r0, r0, hw0(boot_pc)
198 }
199 {
200 add r1, r1, r5
201 add r0, r0, r5
202 }
203 ld r0, r0
204 ld sp, r1
205 shli r4, r4, CPU_SHIFT
206 bfins r4, sp, 0, CPU_SHIFT-1
207 mtspr SPR_SYSTEM_SAVE_K_0, r4 /* save ksp0 + cpu */
208 {
209 move lr, zero /* stop backtraces in the called function */
210 jr r0
211 }
212 ENDPROC(_start)
213
214__PAGE_ALIGNED_BSS
215 .align PAGE_SIZE
216ENTRY(empty_zero_page)
217 .fill PAGE_SIZE,1,0
218 END(empty_zero_page)
219
220 .macro PTE cpa, bits1
221 .quad HV_PTE_PAGE | HV_PTE_DIRTY | HV_PTE_PRESENT | HV_PTE_ACCESSED |\
222 HV_PTE_GLOBAL | (HV_PTE_MODE_CACHE_NO_L3 << HV_PTE_INDEX_MODE) |\
223 (\bits1) | (HV_CPA_TO_PTFN(\cpa) << HV_PTE_INDEX_PTFN)
224 .endm
225
226__PAGE_ALIGNED_DATA
227 .align PAGE_SIZE
228ENTRY(swapper_pg_dir)
229 .org swapper_pg_dir + PGD_INDEX(PAGE_OFFSET) * HV_PTE_SIZE
230.Lsv_data_pmd:
231 .quad 0 /* PTE temp_data_pmd - PAGE_OFFSET, 0 */
232 .org swapper_pg_dir + PGD_INDEX(MEM_SV_START) * HV_PTE_SIZE
233.Lsv_code_pmd:
234 .quad 0 /* PTE temp_code_pmd - PAGE_OFFSET, 0 */
235 .org swapper_pg_dir + SIZEOF_PGD
236 END(swapper_pg_dir)
237
238 .align HV_PAGE_TABLE_ALIGN
239ENTRY(temp_data_pmd)
240 /*
241 * We fill the PAGE_OFFSET pmd with huge pages with
242 * VA = PA + PAGE_OFFSET. We remap things with more precise access
243 * permissions later.
244 */
245 .set addr, 0
246 .rept PTRS_PER_PMD
247 PTE addr, HV_PTE_READABLE | HV_PTE_WRITABLE
248 .set addr, addr + HPAGE_SIZE
249 .endr
250 .org temp_data_pmd + SIZEOF_PMD
251 END(temp_data_pmd)
252
253 .align HV_PAGE_TABLE_ALIGN
254ENTRY(temp_code_pmd)
255 /*
256 * We fill the MEM_SV_START pmd with huge pages with
257 * VA = PA + PAGE_OFFSET. We remap things with more precise access
258 * permissions later.
259 */
260 .set addr, 0
261 .rept PTRS_PER_PMD
262 PTE addr, HV_PTE_READABLE | HV_PTE_EXECUTABLE
263 .set addr, addr + HPAGE_SIZE
264 .endr
265 .org temp_code_pmd + SIZEOF_PMD
266 END(temp_code_pmd)
267
268 /*
269 * Isolate swapper_pgprot to its own cache line, since each cpu
270 * starting up will read it using VA-is-PA and local homing.
271 * This would otherwise likely conflict with other data on the cache
272 * line, once we have set its permanent home in the page tables.
273 */
274 __INITDATA
275 .align CHIP_L2_LINE_SIZE()
276ENTRY(swapper_pgprot)
277 .quad HV_PTE_PRESENT | (HV_PTE_MODE_CACHE_NO_L3 << HV_PTE_INDEX_MODE)
278 .align CHIP_L2_LINE_SIZE()
279 END(swapper_pgprot)