2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
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.
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
17 #include <linux/linkage.h>
18 #include <linux/init.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>
29 * This module contains the entry code for kernel images. It performs the
30 * minimal setup needed to call the generic C routines.
35 /* Notify the hypervisor of what version of the API we want */
38 movei r2, TILE_CHIP_REV
41 moveli r0, _HV_VERSION
44 /* Get a reasonable default ASID in r0 */
49 /* Install the default page table */
51 moveli r6, lo16(swapper_pgprot - PAGE_OFFSET)
52 move r4, r0 /* use starting ASID of range for this page table */
55 moveli r0, lo16(swapper_pg_dir - PAGE_OFFSET)
56 auli r6, r6, ha16(swapper_pgprot - PAGE_OFFSET)
64 auli r0, r0, ha16(swapper_pg_dir - PAGE_OFFSET)
68 move r1, zero /* high 32 bits of CPA is zero */
80 /* Get our processor number and save it away in SAVE_K_0. */
81 jal hv_inquire_topology
82 mulll_uu r4, r1, r2 /* r1 == y, r2 == width */
83 add r4, r4, r0 /* r0 == x, so r4 == cpu == y*width + x */
87 * Load up our per-cpu offset. When the first (master) tile
88 * boots, this value is still zero, so we will load boot_pc
89 * with start_kernel, and boot_sp with init_stack + THREAD_SIZE.
90 * The master tile initializes the per-cpu offset array, so that
91 * when subsequent (secondary) tiles boot, they will instead load
92 * from their per-cpu versions of boot_sp and boot_pc.
94 moveli r5, lo16(__per_cpu_offset)
95 auli r5, r5, ha16(__per_cpu_offset)
101 * Save the width and height to the smp_topology variable
104 moveli r0, lo16(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
105 auli r0, r0, ha16(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
108 addi r0, r0, (HV_TOPOLOGY_HEIGHT_OFFSET - HV_TOPOLOGY_WIDTH_OFFSET)
116 /* Load and go with the correct pc and sp. */
118 addli r1, r5, lo16(boot_sp)
119 addli r0, r5, lo16(boot_pc)
122 auli r1, r1, ha16(boot_sp)
123 auli r0, r0, ha16(boot_pc)
128 mtspr SPR_SYSTEM_SAVE_K_0, r4 /* save ksp0 + cpu */
129 addi sp, sp, -STACK_TOP_DELTA
131 move lr, zero /* stop backtraces in the called function */
136 .section ".bss.page_aligned","w"
138 ENTRY(empty_zero_page)
142 .macro PTE va, cpa, bits1, no_org=0
144 .org swapper_pg_dir + HV_L1_INDEX(\va) * HV_PTE_SIZE
146 .word HV_PTE_PAGE | HV_PTE_DIRTY | HV_PTE_PRESENT | HV_PTE_ACCESSED | \
147 (HV_PTE_MODE_CACHE_NO_L3 << HV_PTE_INDEX_MODE)
148 .word (\bits1) | (HV_CPA_TO_PFN(\cpa) << HV_PTE_INDEX_PFN)
151 .section ".data.page_aligned","wa"
153 ENTRY(swapper_pg_dir)
155 * All data pages from PAGE_OFFSET to MEM_USER_INTRPT are mapped as
156 * VA = PA + PAGE_OFFSET. We remap things with more precise access
157 * permissions and more respect for size of RAM later.
160 .rept (MEM_USER_INTRPT - PAGE_OFFSET) >> PGDIR_SHIFT
161 PTE addr + PAGE_OFFSET, addr, HV_PTE_READABLE | HV_PTE_WRITABLE
162 .set addr, addr + PGDIR_SIZE
165 /* The true text VAs are mapped as VA = PA + MEM_SV_INTRPT */
166 PTE MEM_SV_INTRPT, 0, HV_PTE_READABLE | HV_PTE_EXECUTABLE
167 .org swapper_pg_dir + HV_L1_SIZE
171 * Isolate swapper_pgprot to its own cache line, since each cpu
172 * starting up will read it using VA-is-PA and local homing.
173 * This would otherwise likely conflict with other data on the cache
174 * line, once we have set its permanent home in the page tables.
177 .align CHIP_L2_LINE_SIZE()
178 ENTRY(swapper_pgprot)
179 PTE 0, 0, HV_PTE_READABLE | HV_PTE_WRITABLE, 1
180 .align CHIP_L2_LINE_SIZE()