mp_exception.S revision 91783
1309576Sglebius/*-
2 * Copyright (c) 2002 Jake Burkholder.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/sparc64/sparc64/mp_exception.S 91783 2002-03-07 06:01:40Z jake $
27 */
28
29#include <machine/asi.h>
30#include <machine/ktr.h>
31#include <machine/asmacros.h>
32#include <machine/pstate.h>
33
34#include "assym.s"
35
36	.register	%g2, #ignore
37	.register	%g3, #ignore
38
39#if 0
40#define	IPI_WAIT(r1, r2, r3) \
41	ATOMIC_DEC_INT(r1, r2, r3) ; \
429:	lduw	[r1], r2 ; \
43	brnz,a,pn r2, 9b ; \
44	 nop
45#else
46#define	IPI_WAIT(r1, r2, r3)
47#endif
48
49/*
50 * Trigger a softint at the desired level.
51 */
52ENTRY(tl_ipi_level)
53	lduw	[%g5 + ILA_LEVEL], %g2
54
55	mov	1, %g1
56	sllx	%g1, %g2, %g1
57	wr	%g1, 0, %asr20
58
59	IPI_WAIT(%g5, %g1, %g2)
60	retry
61END(tl_ipi_level)
62
63ENTRY(tl_ipi_test)
64#if KTR_COMPILE & KTR_SMP
65	CATR(KTR_SMP, "ipi_test: cpuid=%d mid=%d d1=%#lx d2=%#lx"
66	    , %g1, %g2, %g3, 7, 8, 9)
67	lduw	[PCPU(CPUID)], %g2
68	stx	%g2, [%g1 + KTR_PARM1]
69	lduw	[PCPU(MID)], %g2
70	stx	%g2, [%g1 + KTR_PARM2]
71	stx	%g4, [%g1 + KTR_PARM3]
72	stx	%g5, [%g1 + KTR_PARM4]
739:
74#endif
75	retry
76END(tl_ipi_test)
77
78/*
79 * Demap a page from the dtlb and/or itlb.
80 */
81ENTRY(tl_ipi_tlb_page_demap)
82#if KTR_COMPILE & KTR_SMP
83	CATR(KTR_SMP, "ipi_tlb_page_demap: pm=%p va=%#lx"
84	    , %g1, %g2, %g3, 7, 8, 9)
85	ldx	[%g5 + ITA_PMAP], %g2
86	stx	%g2, [%g1 + KTR_PARM1]
87	ldx	[%g5 + ITA_VA], %g2
88	stx	%g2, [%g1 + KTR_PARM2]
899:
90#endif
91
92	ldx	[%g5 + ITA_PMAP], %g1
93
94	SET(kernel_pmap_store, %g3, %g2)
95	mov	TLB_DEMAP_NUCLEUS | TLB_DEMAP_PAGE, %g3
96
97	cmp	%g1, %g2
98	movne	%xcc, TLB_DEMAP_PRIMARY | TLB_DEMAP_PAGE, %g3
99
100	ldx	[%g5 + ITA_TLB], %g1
101	ldx	[%g5 + ITA_VA], %g2
102	or	%g2, %g3, %g2
103
104	andcc	%g1, TLB_DTLB, %g0
105	bz,a,pn	%xcc, 1f
106	 nop
107	stxa	%g0, [%g2] ASI_DMMU_DEMAP
108	membar	#Sync
109
1101:	andcc	%g1, TLB_ITLB, %g0
111	bz,a,pn	%xcc, 2f
112	 nop
113	stxa	%g0, [%g2] ASI_IMMU_DEMAP
114	membar	#Sync
115
1162:	IPI_WAIT(%g5, %g1, %g2)
117	retry
118END(tl_ipi_tlb_page_demap)
119
120/*
121 * Demap a range of pages from the dtlb and itlb.
122 */
123ENTRY(tl_ipi_tlb_range_demap)
124#if KTR_COMPILE & KTR_SMP
125	CATR(KTR_SMP, "ipi_tlb_range_demap: pm=%p start=%#lx end=%#lx"
126	    , %g1, %g2, %g3, 7, 8, 9)
127	ldx	[%g5 + ITA_PMAP], %g2
128	stx	%g2, [%g1 + KTR_PARM1]
129	ldx	[%g5 + ITA_START], %g2
130	stx	%g2, [%g1 + KTR_PARM2]
131	ldx	[%g5 + ITA_END], %g2
132	stx	%g2, [%g1 + KTR_PARM3]
1339:
134#endif
135
136	ldx	[%g5 + ITA_PMAP], %g1
137
138	SET(kernel_pmap_store, %g3, %g2)
139	mov	TLB_DEMAP_NUCLEUS | TLB_DEMAP_PAGE, %g3
140
141	cmp	%g1, %g2
142	movne	%xcc, TLB_DEMAP_PRIMARY | TLB_DEMAP_PAGE, %g3
143
144	ldx	[%g5 + ITA_START], %g1
145	ldx	[%g5 + ITA_END], %g2
146
147	set	PAGE_SIZE, %g6
148
1491:	or	%g1, %g3, %g4
150	stxa	%g0, [%g4] ASI_DMMU_DEMAP
151	stxa	%g0, [%g4] ASI_IMMU_DEMAP
152	membar	#Sync
153
154	add	%g1, %g6, %g1
155	cmp	%g1, %g2
156	blt,a,pt %xcc, 1b
157	 nop
158
159	IPI_WAIT(%g5, %g1, %g2)
160	retry
161END(tl_ipi_tlb_range_demap)
162
163/*
164 * Demap the primary context from the dtlb and itlb.
165 */
166ENTRY(tl_ipi_tlb_context_demap)
167#if KTR_COMPILE & KTR_SMP
168	CATR(KTR_SMP, "ipi_tlb_page_demap: pm=%p va=%#lx"
169	    , %g1, %g2, %g3, 7, 8, 9)
170	ldx	[%g5 + ITA_PMAP], %g2
171	stx	%g2, [%g1 + KTR_PARM1]
172	ldx	[%g5 + ITA_VA], %g2
173	stx	%g2, [%g1 + KTR_PARM2]
1749:
175#endif
176
177	mov	TLB_DEMAP_PRIMARY | TLB_DEMAP_CONTEXT, %g1
178	stxa	%g0, [%g1] ASI_DMMU_DEMAP
179	stxa	%g0, [%g1] ASI_IMMU_DEMAP
180	membar	#Sync
181
182	IPI_WAIT(%g5, %g1, %g2)
183	retry
184END(tl_ipi_tlb_context_demap)
185