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/types.h>
22 #include <asm/asm-offsets.h>
23 #include <hv/hypervisor.h>
28 * First, some definitions that apply to all the code in the file.
31 /* Locals (caller-save) */
35 /* What we save where in the stack frame; must include all callee-saves. */
51 * r0 low word of the new context PA to install (moved to r_context_lo)
52 * r1 high word of the new context PA to install (moved to r_context_hi)
53 * r2 low word of PTE to use for context access (moved to r_access_lo)
54 * r3 high word of PTE to use for context access (moved to r_access_lo)
55 * r4 ASID to use for new context (moved to r_asid)
56 * r5 pointer to cpumask with just this cpu set in it (r_my_cpumask)
59 /* Arguments (caller-save) */
60 #define r_context_lo_in r0
61 #define r_context_hi_in r1
62 #define r_access_lo_in r2
63 #define r_access_hi_in r3
65 #define r_my_cpumask r5
67 /* Locals (callee-save); must not be more than FRAME_xxx above. */
68 #define r_save_ics r30
69 #define r_context_lo r31
70 #define r_context_hi r32
71 #define r_access_lo r33
72 #define r_access_hi r34
75 STD_ENTRY(flush_and_install_context)
77 * Create a stack frame; we can't touch it once we flush the
78 * cache until we install the new page table and flush the TLB.
83 addi sp, sp, -FRAME_SIZE
85 addi r_tmp, sp, FRAME_SP
88 addi r_tmp, sp, FRAME_R30
92 addi r_tmp, sp, FRAME_R31
96 addi r_tmp, sp, FRAME_R32
100 addi r_tmp, sp, FRAME_R33
104 addi r_tmp, sp, FRAME_R34
108 addi r_tmp, sp, FRAME_R35
112 /* Move some arguments to callee-save registers. */
114 move r_context_lo, r_context_lo_in
115 move r_context_hi, r_context_hi_in
118 move r_access_lo, r_access_lo_in
119 move r_access_hi, r_access_hi_in
121 move r_asid, r_asid_in
123 /* Disable interrupts, since we can't use our stack. */
125 mfspr r_save_ics, INTERRUPT_CRITICAL_SECTION
128 mtspr INTERRUPT_CRITICAL_SECTION, r_tmp
130 /* First, flush our L2 cache. */
132 move r0, zero /* cache_pa */
136 auli r2, zero, ha16(HV_FLUSH_EVICT_L2) /* cache_control */
137 move r3, r_my_cpumask /* cache_cpumask */
140 move r4, zero /* tlb_va */
141 move r5, zero /* tlb_length */
144 move r6, zero /* tlb_pgsize */
145 move r7, zero /* tlb_cpumask */
148 move r8, zero /* asids */
149 move r9, zero /* asidcount */
154 /* Now install the new page table. */
156 move r0, r_context_lo
157 move r1, r_context_hi
165 movei r5, HV_CTX_DIRECTIO
167 jal hv_install_context
170 /* Finally, flush the TLB. */
172 movei r0, 0 /* preserve_global */
177 /* Reset interrupts back how they were before. */
178 mtspr INTERRUPT_CRITICAL_SECTION, r_save_ics
180 /* Restore the callee-saved registers and return. */
181 addli lr, sp, FRAME_SIZE
184 addli r_tmp, sp, FRAME_R30
188 addli r_tmp, sp, FRAME_R31
192 addli r_tmp, sp, FRAME_R32
196 addli r_tmp, sp, FRAME_R33
200 addli r_tmp, sp, FRAME_R34
204 addli r_tmp, sp, FRAME_R35
208 addi sp, sp, FRAME_SIZE
211 STD_ENDPROC(flush_and_install_context)