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
14 * This routine is a helper for migrating the home of a set of pages to
15 * a new cpu. See the documentation in homecache.c for more information.
18 #include <linux/linkage.h>
19 #include <linux/threads.h>
21 #include <asm/thread_info.h>
22 #include <asm/types.h>
23 #include <asm/asm-offsets.h>
24 #include <hv/hypervisor.h>
29 * First, some definitions that apply to all the code in the file.
32 /* Locals (caller-save) */
36 /* What we save where in the stack frame; must include all callee-saves. */
52 * r0 low word of the new context PA to install (moved to r_context_lo)
53 * r1 high word of the new context PA to install (moved to r_context_hi)
54 * r2 low word of PTE to use for context access (moved to r_access_lo)
55 * r3 high word of PTE to use for context access (moved to r_access_lo)
56 * r4 ASID to use for new context (moved to r_asid)
57 * r5 pointer to cpumask with just this cpu set in it (r_my_cpumask)
60 /* Arguments (caller-save) */
61 #define r_context_lo_in r0
62 #define r_context_hi_in r1
63 #define r_access_lo_in r2
64 #define r_access_hi_in r3
66 #define r_my_cpumask r5
68 /* Locals (callee-save); must not be more than FRAME_xxx above. */
69 #define r_save_ics r30
70 #define r_context_lo r31
71 #define r_context_hi r32
72 #define r_access_lo r33
73 #define r_access_hi r34
76 STD_ENTRY(flush_and_install_context)
78 * Create a stack frame; we can't touch it once we flush the
79 * cache until we install the new page table and flush the TLB.
84 addi sp, sp, -FRAME_SIZE
86 addi r_tmp, sp, FRAME_SP
89 addi r_tmp, sp, FRAME_R30
93 addi r_tmp, sp, FRAME_R31
97 addi r_tmp, sp, FRAME_R32
101 addi r_tmp, sp, FRAME_R33
105 addi r_tmp, sp, FRAME_R34
109 addi r_tmp, sp, FRAME_R35
113 /* Move some arguments to callee-save registers. */
115 move r_context_lo, r_context_lo_in
116 move r_context_hi, r_context_hi_in
119 move r_access_lo, r_access_lo_in
120 move r_access_hi, r_access_hi_in
122 move r_asid, r_asid_in
124 /* Disable interrupts, since we can't use our stack. */
126 mfspr r_save_ics, INTERRUPT_CRITICAL_SECTION
129 mtspr INTERRUPT_CRITICAL_SECTION, r_tmp
131 /* First, flush our L2 cache. */
133 move r0, zero /* cache_pa */
137 auli r2, zero, ha16(HV_FLUSH_EVICT_L2) /* cache_control */
138 move r3, r_my_cpumask /* cache_cpumask */
141 move r4, zero /* tlb_va */
142 move r5, zero /* tlb_length */
145 move r6, zero /* tlb_pgsize */
146 move r7, zero /* tlb_cpumask */
149 move r8, zero /* asids */
150 move r9, zero /* asidcount */
155 /* Now install the new page table. */
157 move r0, r_context_lo
158 move r1, r_context_hi
166 movei r5, HV_CTX_DIRECTIO
168 jal hv_install_context
171 /* Finally, flush the TLB. */
173 movei r0, 0 /* preserve_global */
178 /* Reset interrupts back how they were before. */
179 mtspr INTERRUPT_CRITICAL_SECTION, r_save_ics
181 /* Restore the callee-saved registers and return. */
182 addli lr, sp, FRAME_SIZE
185 addli r_tmp, sp, FRAME_R30
189 addli r_tmp, sp, FRAME_R31
193 addli r_tmp, sp, FRAME_R32
197 addli r_tmp, sp, FRAME_R33
201 addli r_tmp, sp, FRAME_R34
205 addli r_tmp, sp, FRAME_R35
209 addi sp, sp, FRAME_SIZE
212 STD_ENDPROC(flush_and_install_context)