ctlreg.h revision 1.26 1 /* $NetBSD: ctlreg.h,v 1.26 2001/06/29 23:56:05 eeh Exp $ */
2
3 /*
4 * Copyright (c) 1996-2001 Eduardo Horvath
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
13 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
16 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22 * SUCH DAMAGE.
23 *
24 */
25
26 /*
27 * Sun 4u control registers. (includes address space definitions
28 * and some registers in control space).
29 */
30
31 /*
32 * The Alternate address spaces.
33 *
34 * 0x00-0x7f are privileged
35 * 0x80-0xff can be used by users
36 */
37
38 #define ASI_LITTLE 0x08 /* This bit should make an ASI little endian */
39
40 #define ASI_NUCLEUS 0x04 /* [4u] kernel address space */
41 #define ASI_NUCLEUS_LITTLE 0x0c /* [4u] kernel address space, little endian */
42
43 #define ASI_AS_IF_USER_PRIMARY 0x10 /* [4u] primary user address space */
44 #define ASI_AS_IF_USER_SECONDARY 0x11 /* [4u] secondary user address space */
45
46 #define ASI_PHYS_CACHED 0x14 /* [4u] MMU bypass to main memory */
47 #define ASI_PHYS_NON_CACHED 0x15 /* [4u] MMU bypass to I/O location */
48
49 #define ASI_AS_IF_USER_PRIMARY_LITTLE 0x18 /* [4u] primary user address space, little endian */
50 #define ASI_AS_IF_USER_SECONDARY_LITTIE 0x19 /* [4u] secondary user address space, little endian */
51
52 #define ASI_PHYS_CACHED_LITTLE 0x1c /* [4u] MMU bypass to main memory, little endian */
53 #define ASI_PHYS_NON_CACHED_LITTLE 0x1d /* [4u] MMU bypass to I/O location, little endian */
54
55 #define ASI_NUCLEUS_QUAD_LDD 0x24 /* [4u] use w/LDDA to load 128-bit item */
56 #define ASI_NUCLEUS_QUAD_LDD_LITTLE 0x2c /* [4u] use w/LDDA to load 128-bit item, little endian */
57
58 #define ASI_FLUSH_D_PAGE_PRIMARY 0x38 /* [4u] flush D-cache page using primary context */
59 #define ASI_FLUSH_D_PAGE_SECONDARY 0x39 /* [4u] flush D-cache page using secondary context */
60 #define ASI_FLUSH_D_CTX_PRIMARY 0x3a /* [4u] flush D-cache context using primary context */
61 #define ASI_FLUSH_D_CTX_SECONDARY 0x3b /* [4u] flush D-cache context using secondary context */
62
63 #define ASI_LSU_CONTROL_REGISTER 0x45 /* [4u] load/store unit control register */
64
65 #define ASI_DCACHE_DATA 0x46 /* [4u] diagnostic access to D-cache data RAM */
66 #define ASI_DCACHE_TAG 0x47 /* [4u] diagnostic access to D-cache tag RAM */
67
68 #define ASI_INTR_DISPATCH_STATUS 0x48 /* [4u] interrupt dispatch status register */
69 #define ASI_INTR_RECEIVE 0x49 /* [4u] interrupt receive status register */
70 #define ASI_MID_REG 0x4a /* [4u] hardware config and MID */
71 #define ASI_ERROR_EN_REG 0x4b /* [4u] asynchronous error enables */
72 #define ASI_AFSR 0x4c /* [4u] asynchronous fault status register */
73 #define ASI_AFAR 0x4d /* [4u] asynchronous fault address register */
74
75 #define ASI_ICACHE_DATA 0x66 /* [4u] diagnostic access to D-cache data RAM */
76 #define ASI_ICACHE_TAG 0x67 /* [4u] diagnostic access to D-cache tag RAM */
77 #define ASI_FLUSH_I_PAGE_PRIMARY 0x68 /* [4u] flush D-cache page using primary context */
78 #define ASI_FLUSH_I_PAGE_SECONDARY 0x69 /* [4u] flush D-cache page using secondary context */
79 #define ASI_FLUSH_I_CTX_PRIMARY 0x6a /* [4u] flush D-cache context using primary context */
80 #define ASI_FLUSH_I_CTX_SECONDARY 0x6b /* [4u] flush D-cache context using secondary context */
81
82 #define ASI_BLOCK_AS_IF_USER_PRIMARY 0x70 /* [4u] primary user address space, block loads/stores */
83 #define ASI_BLOCK_AS_IF_USER_SECONDARY 0x71 /* [4u] secondary user address space, block loads/stores */
84
85 #define ASI_ECACHE_DIAG 0x76 /* [4u] diag access to E-cache tag and data */
86 #define ASI_DATAPATH_ERR_REG_WRITE 0x77 /* [4u] ASI is reused */
87
88 #define ASI_BLOCK_AS_IF_USER_PRIMARY_LITTLE 0x78 /* [4u] primary user address space, block loads/stores */
89 #define ASI_BLOCK_AS_IF_USER_SECONDARY_LITTLE 0x79 /* [4u] secondary user address space, block loads/stores */
90
91 #define ASI_INTERRUPT_RECEIVE_DATA 0x7f /* [4u] interrupt receive data registers {0,1,2} */
92 #define ASI_DATAPATH_ERR_REG_READ 0x7f /* [4u] read access to datapath error registers (ASI reused) */
93
94 #define ASI_PRIMARY 0x80 /* [4u] primary address space */
95 #define ASI_SECONDARY 0x81 /* [4u] secondary address space */
96 #define ASI_PRIMARY_NO_FAULT 0x82 /* [4u] primary address space, no fault */
97 #define ASI_SECONDARY_NO_FAULT 0x83 /* [4u] secondary address space, no fault */
98
99 #define ASI_PRIMARY_LITTLE 0x88 /* [4u] primary address space, little endian */
100 #define ASI_SECONDARY_LITTLE 0x89 /* [4u] secondary address space, little endian */
101 #define ASI_PRIMARY_NO_FAULT_LITTLE 0x8a /* [4u] primary address space, no fault, little endian */
102 #define ASI_SECONDARY_NO_FAULT_LITTLE 0x8b /* [4u] secondary address space, no fault, little endian */
103
104 #define ASI_PST8_PRIMARY 0xc0 /* [VIS] Eight 8-bit partial store, primary */
105 #define ASI_PST8_SECONDARY 0xc1 /* [VIS] Eight 8-bit partial store, secondary */
106 #define ASI_PST16_PRIMARY 0xc2 /* [VIS] Four 16-bit partial store, primary */
107 #define ASI_PST16_SECONDARY 0xc3 /* [VIS] Fout 16-bit partial store, secondary */
108 #define ASI_PST32_PRIMARY 0xc4 /* [VIS] Two 32-bit partial store, primary */
109 #define ASI_PST32_SECONDARY 0xc5 /* [VIS] Two 32-bit partial store, secondary */
110
111 #define ASI_PST8_PRIMARY_LITTLE 0xc8 /* [VIS] Eight 8-bit partial store, primary, little endian */
112 #define ASI_PST8_SECONDARY_LITTLE 0xc9 /* [VIS] Eight 8-bit partial store, secondary, little endian */
113 #define ASI_PST16_PRIMARY_LITTLE 0xca /* [VIS] Four 16-bit partial store, primary, little endian */
114 #define ASI_PST16_SECONDARY_LITTLE 0xcb /* [VIS] Fout 16-bit partial store, secondary, little endian */
115 #define ASI_PST32_PRIMARY_LITTLE 0xcc /* [VIS] Two 32-bit partial store, primary, little endian */
116 #define ASI_PST32_SECONDARY_LITTLE 0xcd /* [VIS] Two 32-bit partial store, secondary, little endian */
117
118 #define ASI_FL8_PRIMARY 0xd0 /* [VIS] One 8-bit load/store floating, primary */
119 #define ASI_FL8_SECONDARY 0xd1 /* [VIS] One 8-bit load/store floating, secondary */
120 #define ASI_FL16_PRIMARY 0xd2 /* [VIS] One 16-bit load/store floating, primary */
121 #define ASI_FL16_SECONDARY 0xd3 /* [VIS] One 16-bit load/store floating, secondary */
122
123 #define ASI_FL8_PRIMARY_LITTLE 0xd8 /* [VIS] One 8-bit load/store floating, primary, little endian */
124 #define ASI_FL8_SECONDARY_LITTLE 0xd9 /* [VIS] One 8-bit load/store floating, secondary, little endian */
125 #define ASI_FL16_PRIMARY_LITTLE 0xda /* [VIS] One 16-bit load/store floating, primary, little endian */
126 #define ASI_FL16_SECONDARY_LITTLE 0xdb /* [VIS] One 16-bit load/store floating, secondary, little endian */
127
128 #define ASI_BLOCK_COMMIT_PRIMARY 0xe0 /* [4u] block store with commit, primary */
129 #define ASI_BLOCK_COMMIT_SECONDARY 0xe1 /* [4u] block store with commit, secondary */
130 #define ASI_BLOCK_PRIMARY 0xf0 /* [4u] block load/store, primary */
131 #define ASI_BLOCK_SECONDARY 0xf1 /* [4u] block load/store, secondary */
132 #define ASI_BLOCK_PRIMARY_LITTLE 0xf8 /* [4u] block load/store, primary, little endian */
133 #define ASI_BLOCK_SECONDARY_LITTLE 0xf9 /* [4u] block load/store, secondary, little endian */
134
135
136 /*
137 * These are the shorter names used by Solaris
138 */
139
140 #define ASI_N ASI_NUCLEUS
141 #define ASI_NL ASI_NUCLEUS_LITTLE
142 #define ASI_AIUP ASI_AS_IF_USER_PRIMARY
143 #define ASI_AIUS ASI_AS_IF_USER_SECONDARY
144 #define ASI_AIUPL ASI_AS_IF_USER_PRIMARY_LITTLE
145 #define ASI_AIUSL ASI_AS_IF_USER_SECONDARY_LITTLE
146 #define ASI_P ASI_PRIMARY
147 #define ASI_S ASI_SECONDARY
148 #define ASI_PNF ASI_PRIMARY_NO_FAULT
149 #define ASI_SNF ASI_SECONDARY_NO_FAULT
150 #define ASI_PL ASI_PRIMARY_LITTLE
151 #define ASI_SL ASI_SECONDARY_LITTLE
152 #define ASI_PNFL ASI_PRIMARY_NO_FAULT_LITTLE
153 #define ASI_SNFL ASI_SECONDARY_NO_FAULT_LITTLE
154 #define ASI_FL8_P ASI_FL8_PRIMARY
155 #define ASI_FL8_S ASI_FL8_SECONDARY
156 #define ASI_FL16_P ASI_FL16_PRIMARY
157 #define ASI_FL16_S ASI_FL16_SECONDARY
158 #define ASI_FL8_PL ASI_FL8_PRIMARY_LITTLE
159 #define ASI_FL8_SL ASI_FL8_SECONDARY_LITTLE
160 #define ASI_FL16_PL ASI_FL16_PRIMARY_LITTLE
161 #define ASI_FL16_SL ASI_FL16_SECONDARY_LITTLE
162 #define ASI_BLK_AIUP ASI_BLOCK_AS_IF_USER_PRIMARY
163 #define ASI_BLK_AIUPL ASI_BLOCK_AS_IF_USER_PRIMARY_LITTLE
164 #define ASI_BLK_AIUS ASI_BLOCK_AS_IF_USER_SECONDARY
165 #define ASI_BLK_AIUSL ASI_BLOCK_AS_IF_USER_SECONDARY_LITTLE
166 #define ASI_BLK_COMMIT_P ASI_BLOCK_COMMIT_PRIMARY
167 #define ASI_BLK_COMMIT_PRIMARY ASI_BLOCK_COMMIT_PRIMARY
168 #define ASI_BLK_COMMIT_S ASI_BLOCK_COMMIT_SECONDARY
169 #define ASI_BLK_COMMIT_SECONDARY ASI_BLOCK_COMMIT_SECONDARY
170 #define ASI_BLK_P ASI_BLOCK_PRIMARY
171 #define ASI_BLK_PL ASI_BLOCK_PRIMARY_LITTLE
172 #define ASI_BLK_S ASI_BLOCK_SECONDARY
173 #define ASI_BLK_SL ASI_BLOCK_SECONDARY_LITTLE
174
175 #define PHYS_ASI(x) (((x) | 0x09) == 0x1d)
176 #define LITTLE_ASI(x) ((x) & ASI_LITTLE)
177
178 /*
179 * The following are 4u control registers
180 */
181
182
183 /* Get the CPU's UPAID */
184 #define UPA_CR_MID(x) (((x)>>17)&0x1f)
185 #define CPU_UPAID UPA_CR_MID(ldxa(0, ASI_MID_REG))
186
187 /*
188 * [4u] MMU and Cache Control Register (MCCR)
189 * use ASI = 0x45
190 */
191 #define ASI_MCCR ASI_LSU_CONTROL_REGISTER
192 #define MCCR 0x00
193
194 /* MCCR Bits and their meanings */
195 #define MCCR_DMMU_EN 0x08
196 #define MCCR_IMMU_EN 0x04
197 #define MCCR_DCACHE_EN 0x02
198 #define MCCR_ICACHE_EN 0x01
199
200
201 /*
202 * MMU control registers
203 */
204
205 /* Choose an MMU */
206 #define ASI_DMMU 0x58
207 #define ASI_IMMU 0x50
208
209 /* Other assorted MMU ASIs */
210 #define ASI_IMMU_8KPTR 0x51
211 #define ASI_IMMU_64KPTR 0x52
212 #define ASI_IMMU_DATA_IN 0x54
213 #define ASI_IMMU_TLB_DATA 0x55
214 #define ASI_IMMU_TLB_TAG 0x56
215 #define ASI_DMMU_8KPTR 0x59
216 #define ASI_DMMU_64KPTR 0x5a
217 #define ASI_DMMU_DATA_IN 0x5c
218 #define ASI_DMMU_TLB_DATA 0x5d
219 #define ASI_DMMU_TLB_TAG 0x5e
220
221 /*
222 * The following are the control registers
223 * They work on both MMUs unless noted.
224 *
225 * Register contents are defined later on individual registers.
226 */
227 #define TSB_TAG_TARGET 0x0
228 #define TLB_DATA_IN 0x0
229 #define CTX_PRIMARY 0x08 /* primary context -- DMMU only */
230 #define CTX_SECONDARY 0x10 /* secondary context -- DMMU only */
231 #define SFSR 0x18
232 #define SFAR 0x20 /* fault address -- DMMU only */
233 #define TSB 0x28
234 #define TLB_TAG_ACCESS 0x30
235 #define VIRTUAL_WATCHPOINT 0x38
236 #define PHYSICAL_WATCHPOINT 0x40
237
238 /* Tag Target bits */
239 #define TAG_TARGET_VA_MASK 0x03ffffffffffffffffLL
240 #define TAG_TARGET_VA(x) (((x)<<22)&TAG_TARGET_VA_MASK)
241 #define TAG_TARGET_CONTEXT(x) ((x)>>48)
242 #define TAG_TARGET(c,v) ((((uint64_t)c)<<48)|(((uint64_t)v)&TAG_TARGET_VA_MASK))
243
244 /* SFSR bits for both D_SFSR and I_SFSR */
245 #define SFSR_ASI(x) ((x)>>16)
246 #define SFSR_FT_VA_OOR_2 0x02000 /* IMMU: jumpl or return to unsupportd VA */
247 #define SFSR_FT_VA_OOR_1 0x01000 /* fault at unsupported VA */
248 #define SFSR_FT_NFO 0x00800 /* DMMU: Access to page marked NFO */
249 #define SFSR_ILL_ASI 0x00400 /* DMMU: Illegal (unsupported) ASI */
250 #define SFSR_FT_IO_ATOMIC 0x00200 /* DMMU: Atomic access to noncacheable page */
251 #define SFSR_FT_ILL_NF 0x00100 /* DMMU: NF load or flush to page marked E (has side effects) */
252 #define SFSR_FT_PRIV 0x00080 /* Privilege violation */
253 #define SFSR_FT_E 0x00040 /* DMUU: value of E bit associated address */
254 #define SFSR_CTXT(x) (((x)>>4)&0x3)
255 #define SFSR_CTXT_IS_PRIM(x) (SFSR_CTXT(x)==0x00)
256 #define SFSR_CTXT_IS_SECOND(x) (SFSR_CTXT(x)==0x01)
257 #define SFSR_CTXT_IS_NUCLEUS(x) (SFSR_CTXT(x)==0x02)
258 #define SFSR_PRIV 0x00008 /* value of PSTATE.PRIV for faulting access */
259 #define SFSR_W 0x00004 /* DMMU: attempted write */
260 #define SFSR_OW 0x00002 /* Overwrite; prev vault was still valid */
261 #define SFSR_FV 0x00001 /* Fault is valid */
262 #define SFSR_FT (SFSR_FT_VA_OOR_2|SFSR_FT_VA_OOR_1|SFSR_FT_NFO|SFSR_ILL_ASI|SFSR_FT_IO_ATOMIC|SFSR_FT_ILL_NF|SFSR_FT_PRIV)
263
264 #if 0
265 /* Old bits */
266 #define SFSR_BITS "\40\16VAT\15VAD\14NFO\13ASI\12A\11NF\10PRIV\7E\6NUCLEUS\5SECONDCTX\4PRIV\3W\2OW\1FV"
267 #else
268 /* New bits */
269 #define SFSR_BITS "\177\20" \
270 "f\20\30ASI\0" "b\16VAT\0" "b\15VAD\0" "b\14NFO\0" "b\13ASI\0" "b\12A\0" "b\11NF\0" "b\10PRIV\0" \
271 "b\7E\0" "b\6NUCLEUS\0" "b\5SECONDCTX\0" "b\4PRIV\0" "b\3W\0" "b\2OW\0" "b\1FV\0"
272 #endif
273
274 /* ASFR bits */
275 #define ASFR_ME 0x100000000LL
276 #define ASFR_PRIV 0x080000000LL
277 #define ASFR_ISAP 0x040000000LL
278 #define ASFR_ETP 0x020000000LL
279 #define ASFR_IVUE 0x010000000LL
280 #define ASFR_TO 0x008000000LL
281 #define ASFR_BERR 0x004000000LL
282 #define ASFR_LDP 0x002000000LL
283 #define ASFR_CP 0x001000000LL
284 #define ASFR_WP 0x000800000LL
285 #define ASFR_EDP 0x000400000LL
286 #define ASFR_UE 0x000200000LL
287 #define ASFR_CE 0x000100000LL
288 #define ASFR_ETS 0x0000f0000LL
289 #define ASFT_P_SYND 0x00000ffffLL
290
291 #define AFSR_BITS "\177\20" \
292 "b\40ME\0" "b\37PRIV\0" "b\36ISAP\0" "b\35ETP\0" \
293 "b\34IVUE\0" "b\33TO\0" "b\32BERR\0" "b\31LDP\0" \
294 "b\30CP\0" "b\27WP\0" "b\26EDP\0" "b\25UE\0" \
295 "b\24CE\0" "f\20\4ETS\0" "f\0\20P_SYND\0"
296
297 /*
298 * Here's the spitfire TSB control register bits.
299 *
300 * Each TSB entry is 16-bytes wide. The TSB must be size aligned
301 */
302 #define TSB_SIZE_512 0x0 /* 8kB, etc. */
303 #define TSB_SIZE_1K 0x01
304 #define TSB_SIZE_2K 0x02
305 #define TSB_SIZE_4K 0x03
306 #define TSB_SIZE_8K 0x04
307 #define TSB_SIZE_16K 0x05
308 #define TSB_SIZE_32K 0x06
309 #define TSB_SIZE_64K 0x07
310 #define TSB_SPLIT 0x1000
311 #define TSB_BASE 0xffffffffffffe000
312
313 /* TLB Tag Access bits */
314 #define TLB_TAG_ACCESS_VA 0xffffffffffffe000
315 #define TLB_TAG_ACCESS_CTX 0x0000000000001fff
316
317 /*
318 * TLB demap registers. TTEs are defined in v9pte.h
319 *
320 * Use the address space to select between IMMU and DMMU.
321 * The address of the register selects which context register
322 * to read the ASI from.
323 *
324 * The data stored in the register is interpreted as the VA to
325 * use. The DEMAP_CTX_<> registers ignore the address and demap the
326 * entire ASI.
327 *
328 */
329 #define ASI_IMMU_DEMAP 0x57 /* [4u] IMMU TLB demap */
330 #define ASI_DMMU_DEMAP 0x5f /* [4u] IMMU TLB demap */
331
332 #define DEMAP_PAGE_NUCLEUS ((0x02)<<4) /* Demap page from kernel AS */
333 #define DEMAP_PAGE_PRIMARY ((0x00)<<4) /* Demap a page from primary CTXT */
334 #define DEMAP_PAGE_SECONDARY ((0x01)<<4) /* Demap page from secondary CTXT (DMMU only) */
335 #define DEMAP_CTX_NUCLEUS ((0x06)<<4) /* Demap all of kernel CTXT */
336 #define DEMAP_CTX_PRIMARY ((0x04)<<4) /* Demap all of primary CTXT */
337 #define DEMAP_CTX_SECONDARY ((0x05)<<4) /* Demap all of secondary CTXT */
338
339 /*
340 * Interrupt registers. This really gets hairy.
341 */
342
343 /* IRSR -- Interrupt Receive Status Ragister */
344 #define ASI_IRSR 0x49
345 #define IRSR 0x00
346 #define IRSR_BUSY 0x020
347 #define IRSR_MID(x) (x&0x1f)
348
349 /* IRDR -- Interrupt Receive Data Registers */
350 #define ASI_IRDR 0x7f
351 #define IRDR_0H 0x40
352 #define IRDR_0L 0x48 /* unimplemented */
353 #define IRDR_1H 0x50
354 #define IRDR_1L 0x58 /* unimplemented */
355 #define IRDR_2H 0x60
356 #define IRDR_2L 0x68 /* unimplemented */
357 #define IRDR_3H 0x70 /* unimplemented */
358 #define IRDR_3L 0x78 /* unimplemented */
359
360 /* SOFTINT ASRs */
361 #define SET_SOFTINT %asr20 /* Sets these bits */
362 #define CLEAR_SOFTINT %asr21 /* Clears these bits */
363 #define SOFTINT %asr22 /* Reads the register */
364 #define TICK_CMPR %asr23
365
366 #define TICK_INT 0x01 /* level-14 clock tick */
367 #define SOFTINT1 (0x1<<1)
368 #define SOFTINT2 (0x1<<2)
369 #define SOFTINT3 (0x1<<3)
370 #define SOFTINT4 (0x1<<4)
371 #define SOFTINT5 (0x1<<5)
372 #define SOFTINT6 (0x1<<6)
373 #define SOFTINT7 (0x1<<7)
374 #define SOFTINT8 (0x1<<8)
375 #define SOFTINT9 (0x1<<9)
376 #define SOFTINT10 (0x1<<10)
377 #define SOFTINT11 (0x1<<11)
378 #define SOFTINT12 (0x1<<12)
379 #define SOFTINT13 (0x1<<13)
380 #define SOFTINT14 (0x1<<14)
381 #define SOFTINT15 (0x1<<15)
382
383 /* Interrupt Dispatch -- usually reserved for cross-calls */
384 #define ASR_IDSR 0x48 /* Interrupt dispatch status reg */
385 #define IDSR 0x00
386 #define IDSR_NACK 0x02
387 #define IDSR_BUSY 0x01
388
389 #define ASI_INTERRUPT_DISPATCH 0x77 /* [4u] spitfire interrupt dispatch regs */
390 #define IDCR(x) (((x)<<14)&0x70) /* Store anything to this address to dispatch crosscall to CPU (x) */
391 #define IDDR_0H 0x40 /* Store data to send in these regs */
392 #define IDDR_0L 0x48 /* unimplemented */
393 #define IDDR_1H 0x50
394 #define IDDR_1L 0x58 /* unimplemented */
395 #define IDDR_2H 0x60
396 #define IDDR_2L 0x68 /* unimplemented */
397 #define IDDR_3H 0x70 /* unimplemented */
398 #define IDDR_3L 0x78 /* unimplemented */
399
400 /*
401 * Error registers
402 */
403
404 /* Since we won't try to fix async errs, we don't care about the bits in the regs */
405 #define ASI_AFAR 0x4d /* Asynchronous fault address register */
406 #define AFAR 0x00
407 #define ASI_AFSR 0x4c /* Asynchronous fault status register */
408 #define AFSR 0x00
409
410 #define ASI_P_EER 0x4b /* Error enable register */
411 #define P_EER 0x00
412 #define P_EER_ISAPEN 0x04 /* Enable fatal on ISAP */
413 #define P_EER_NCEEN 0x02 /* Enable trap on uncorrectable errs */
414 #define P_EER_CEEN 0x01 /* Enable trap on correctable errs */
415
416 #define ASI_DATAPATH_READ 0x7f /* Read the regs */
417 #define ASI_DATAPATH_WRITE 0x77 /* Write to the regs */
418 #define P_DPER_0 0x00 /* Datapath err reg 0 */
419 #define P_DPER_1 0x18 /* Datapath err reg 1 */
420 #define P_DCR_0 0x20 /* Datapath control reg 0 */
421 #define P_DCR_1 0x38 /* Datapath control reg 0 */
422
423
424 /* From sparc64/asm.h which I think I'll deprecate since it makes bus.h a pain. */
425
426 #ifndef _LOCORE
427 /*
428 * GCC __asm constructs for doing assembly stuff.
429 */
430
431 /*
432 * ``Routines'' to load and store from/to alternate address space.
433 * The location can be a variable, the asi value (address space indicator)
434 * must be a constant.
435 *
436 * N.B.: You can put as many special functions here as you like, since
437 * they cost no kernel space or time if they are not used.
438 *
439 * These were static inline functions, but gcc screws up the constraints
440 * on the address space identifiers (the "n"umeric value part) because
441 * it inlines too late, so we have to use the funny valued-macro syntax.
442 */
443
444 /*
445 * Apparently the definition of bypass ASIs is that they all use the
446 * D$ so we need to flush the D$ to make sure we don't get data pollution.
447 */
448
449 static __inline__ u_char lduba __P((paddr_t loc, int asi));
450 static __inline__ u_short lduha __P((paddr_t loc, int asi));
451 static __inline__ u_int lda __P((paddr_t loc, int asi));
452 static __inline__ int ldswa __P((paddr_t loc, int asi));
453 static __inline__ u_int64_t ldxa __P((paddr_t loc, int asi));
454 static __inline__ u_int64_t ldda __P((paddr_t loc, int asi));
455
456 static __inline__ void stba __P((paddr_t loc, int asi, u_char value));
457 static __inline__ void stha __P((paddr_t loc, int asi, u_short value));
458 static __inline__ void sta __P((paddr_t loc, int asi, u_int value));
459 static __inline__ void stxa __P((paddr_t loc, int asi, u_int64_t value));
460 static __inline__ void stda __P((paddr_t loc, int asi, u_int64_t value));
461
462 #if 0
463 static __inline__ unsigned int casa __P((paddr_t loc, int asi,
464 unsigned int value, unsigned int oldvalue));
465 static __inline__ u_int64_t casxa __P((paddr_t loc, int asi,
466 u_int64_t value, u_int64_t oldvalue));
467 #endif
468
469 #ifdef __arch64__
470 static __inline__ u_char
471 lduba(paddr_t loc, int asi)
472 {
473 register unsigned int _lduba_v;
474
475 if (PHYS_ASI(asi)) {
476 __asm __volatile("wr %3,%%g0,%%asi; "
477 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; "
478 " lduba [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; "
479 " stxa %%g0,[%1] %4; membar #Sync" :
480 "=&r" (_lduba_v), "=r" (loc):
481 "r" ((unsigned long)(loc)),
482 "r" (asi), "n" (ASI_DCACHE_TAG));
483 } else {
484 __asm __volatile("wr %2,%%g0,%%asi; lduba [%1]%%asi,%0" :
485 "=r" (_lduba_v) :
486 "r" ((unsigned long)(loc)), "r" (asi));
487 }
488 return (_lduba_v);
489 }
490 #else
491 static __inline__ u_char
492 lduba(paddr_t loc, int asi)
493 {
494 register unsigned int _lduba_v, _loc_hi, _pstate;
495
496 _loc_hi = (((u_int64_t)loc)>>32);
497 if (PHYS_ASI(asi)) {
498 __asm __volatile("wr %4,%%g0,%%asi; "
499 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; rdpr %%pstate,%1; "
500 " sllx %3,32,%0; or %0,%2,%0; wrpr %1,8,%%pstate; "
501 " membar #Sync; lduba [%0]%%asi,%0; wrpr %1,0,%%pstate; "
502 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" :
503 "=&r" (_lduba_v), "=&r" (_pstate) :
504 "r" ((unsigned long)(loc)), "r" (_loc_hi),
505 "r" (asi), "n" (ASI_DCACHE_TAG));
506 } else {
507 __asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; "
508 " or %0,%1,%0; lduba [%0]%%asi,%0" : "=&r" (_lduba_v) :
509 "r" ((unsigned long)(loc)),
510 "r" (_loc_hi), "r" (asi));
511 }
512 return (_lduba_v);
513 }
514 #endif
515
516 #ifdef __arch64__
517 /* load half-word from alternate address space */
518 static __inline__ u_short
519 lduha(paddr_t loc, int asi)
520 {
521 register unsigned int _lduha_v;
522
523 if (PHYS_ASI(asi)) {
524 __asm __volatile("wr %3,%%g0,%%asi; "
525 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; "
526 " lduha [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; "
527 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lduha_v), "=r" (loc) :
528 "r" ((unsigned long)(loc)),
529 "r" (asi), "n" (ASI_DCACHE_TAG));
530 } else {
531 __asm __volatile("wr %2,%%g0,%%asi; lduha [%1]%%asi,%0" :
532 "=r" (_lduha_v) :
533 "r" ((unsigned long)(loc)), "r" (asi));
534 }
535 return (_lduha_v);
536 }
537 #else
538 /* load half-word from alternate address space */
539 static __inline__ u_short
540 lduha(paddr_t loc, int asi) {
541 register unsigned int _lduha_v, _loc_hi, _pstate;
542
543 _loc_hi = (((u_int64_t)loc)>>32);
544
545 if (PHYS_ASI(asi)) {
546 __asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1; "
547 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate; sllx %3,32,%0; "
548 " or %0,%2,%0; membar #Sync; lduha [%0]%%asi,%0; wrpr %1,0,%%pstate; "
549 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" :
550 "=&r" (_lduha_v), "=&r" (_pstate) :
551 "r" ((unsigned long)(loc)), "r" (_loc_hi),
552 "r" (asi), "n" (ASI_DCACHE_TAG));
553 } else {
554 __asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; "
555 " or %0,%1,%0; lduha [%0]%%asi,%0" : "=&r" (_lduha_v) :
556 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi));
557 }
558 return (_lduha_v);
559 }
560 #endif
561
562
563 #ifdef __arch64__
564 /* load unsigned int from alternate address space */
565 static __inline__ u_int
566 lda(paddr_t loc, int asi)
567 {
568 register unsigned int _lda_v;
569
570 if (PHYS_ASI(asi)) {
571 __asm __volatile("wr %3,%%g0,%%asi; "
572 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; "
573 " lda [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; "
574 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=r" (loc) :
575 "r" ((unsigned long)(loc)),
576 "r" (asi), "n" (ASI_DCACHE_TAG));
577 } else {
578 __asm __volatile("wr %2,%%g0,%%asi; lda [%1]%%asi,%0" :
579 "=r" (_lda_v) :
580 "r" ((unsigned long)(loc)), "r" (asi));
581 }
582 return (_lda_v);
583 }
584
585 /* load signed int from alternate address space */
586 static __inline__ int
587 ldswa(paddr_t loc, int asi)
588 {
589 register int _lda_v;
590
591 if (PHYS_ASI(asi)) {
592 __asm __volatile("wr %3,%%g0,%%asi; "
593 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; "
594 " ldswa [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; "
595 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=r" (loc) :
596 "r" ((unsigned long)(loc)),
597 "r" (asi), "n" (ASI_DCACHE_TAG));
598 } else {
599 __asm __volatile("wr %2,%%g0,%%asi; ldswa [%1]%%asi,%0" :
600 "=r" (_lda_v) :
601 "r" ((unsigned long)(loc)), "r" (asi));
602 }
603 return (_lda_v);
604 }
605 #else /* __arch64__ */
606 /* load unsigned int from alternate address space */
607 static __inline__ u_int
608 lda(paddr_t loc, int asi)
609 {
610 register unsigned int _lda_v, _loc_hi, _pstate;
611
612 _loc_hi = (((u_int64_t)loc)>>32);
613 if (PHYS_ASI(asi)) {
614 __asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1;"
615 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate; "
616 " sllx %3,32,%0; or %0,%2,%0; membar #Sync;lda [%0]%%asi,%0; "
617 " wrpr %1,0,%%pstate; andn %2,0x1f,%1; membar #Sync; "
618 " stxa %%g0,[%1] %5; membar #Sync" : "=&r" (_lda_v), "=&r" (_pstate) :
619 "r" ((unsigned long)(loc)), "r" (_loc_hi),
620 "r" (asi), "n" (ASI_DCACHE_TAG));
621 } else {
622 __asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; "
623 " or %0,%1,%0; lda [%0]%%asi,%0" : "=&r" (_lda_v) :
624 "r" ((unsigned long)(loc)),
625 "r" (_loc_hi), "r" (asi));
626 }
627 return (_lda_v);
628 }
629
630 /* load signed int from alternate address space */
631 static __inline__ int
632 ldswa(paddr_t loc, int asi)
633 {
634 register int _lda_v, _loc_hi, _pstate;
635
636 _loc_hi = (((u_int64_t)loc)>>32);
637 if (PHYS_ASI(asi)) {
638 __asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1;"
639 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate; sllx %3,32,%0;"
640 " or %0,%2,%0; membar #Sync; ldswa [%0]%%asi,%0; wrpr %1,0,%%pstate; "
641 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" :
642 "=&r" (_lda_v), "=&r" (_pstate) :
643 "r" ((unsigned long)(loc)), "r" (_loc_hi),
644 "r" (asi), "n" (ASI_DCACHE_TAG));
645 } else {
646 __asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; "
647 " or %0,%1,%0; ldswa [%0]%%asi,%0" : "=&r" (_lda_v) :
648 "r" ((unsigned long)(loc)),
649 "r" (_loc_hi), "r" (asi));
650 }
651 return (_lda_v);
652 }
653 #endif /* __arch64__ */
654
655 #ifdef __arch64__
656 /* load 64-bit int from alternate address space -- these should never be used */
657 static __inline__ u_int64_t
658 ldda(paddr_t loc, int asi)
659 {
660 register long long _lda_v;
661
662 if (PHYS_ASI(asi)) {
663 __asm __volatile("wr %3,%%g0,%%asi; "
664 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; "
665 " ldda [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; "
666 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=&r" (loc) :
667 "r" ((unsigned long)(loc)),
668 "r" (asi), "n" (ASI_DCACHE_TAG));
669 } else {
670 __asm __volatile("wr %2,%%g0,%%asi; ldda [%1]%%asi,%0" :
671 "=r" (_lda_v) :
672 "r" ((unsigned long)(loc)), "r" (asi));
673 }
674 return (_lda_v);
675 }
676 #else
677 /* load 64-bit int from alternate address space */
678 static __inline__ u_int64_t
679 ldda(paddr_t loc, int asi)
680 {
681 register long long _lda_v, _loc_hi, _pstate;
682
683 _loc_hi = (((u_int64_t)loc)>>32);
684 if (PHYS_ASI(asi)) {
685 __asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1;"
686 " andn %2,0x1f,%0; rdpr %%pstate,%1; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate;"
687 " sllx %3,32,%0; or %0,%2,%0; membar #Sync; ldda [%0]%%asi,%0; wrpr %1,0,%%pstate; "
688 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" :
689 "=&r" (_lda_v), "=&r" (_pstate) :
690 "r" ((unsigned long)(loc)), "r" (_loc_hi),
691 "r" (asi), "n" (ASI_DCACHE_TAG));
692 } else {
693 __asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; "
694 " or %0,%1,%0; ldda [%0]%%asi,%0" : "=&r" (_lda_v) :
695 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi));
696 }
697 return (_lda_v);
698 }
699 #endif
700
701
702 #ifdef __arch64__
703 /* native load 64-bit int from alternate address space w/64-bit compiler*/
704 static __inline__ u_int64_t
705 ldxa(paddr_t loc, int asi)
706 {
707 register unsigned long _lda_v;
708
709 if (PHYS_ASI(asi)) {
710 __asm __volatile("wr %3,%%g0,%%asi; "
711 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; "
712 " ldxa [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; "
713 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=r" (loc) :
714 "r" ((unsigned long)(loc)),
715 "r" (asi), "n" (ASI_DCACHE_TAG));
716 } else {
717 __asm __volatile("wr %2,%%g0,%%asi; ldxa [%1]%%asi,%0" :
718 "=r" (_lda_v) :
719 "r" ((unsigned long)(loc)), "r" (asi));
720 }
721 return (_lda_v);
722 }
723 #else
724 /* native load 64-bit int from alternate address space w/32-bit compiler*/
725 static __inline__ u_int64_t
726 ldxa(paddr_t loc, int asi)
727 {
728 register unsigned long _ldxa_lo, _ldxa_hi, _loc_hi;
729
730 _loc_hi = (((u_int64_t)loc)>>32);
731 if (PHYS_ASI(asi)) {
732 __asm __volatile("wr %4,%%g0,%%asi; "
733 " andn %2,0x1f,%0; rdpr %%pstate,%1; stxa %%g0,[%0] %5; "
734 " sllx %3,32,%0; wrpr %1,8,%%pstate; or %0,%2,%0; membar #Sync; ldxa [%0]%%asi,%0; "
735 " wrpr %1,0,%%pstate; andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync; "
736 " srlx %0,32,%1; srl %0,0,%0" :
737 "=&r" (_ldxa_lo), "=&r" (_ldxa_hi) :
738 "r" ((unsigned long)(loc)), "r" (_loc_hi),
739 "r" (asi), "n" (ASI_DCACHE_TAG));
740 } else {
741 __asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; "
742 " or %0,%2,%0; ldxa [%0]%%asi,%0; srlx %0,32,%1; srl %0,0,%0;" :
743 "=&r" (_ldxa_lo), "=&r" (_ldxa_hi) :
744 "r" ((unsigned long)(loc)), "r" (_loc_hi),
745 "r" (asi));
746 }
747 return ((((int64_t)_ldxa_hi)<<32)|_ldxa_lo);
748 }
749 #endif
750
751 /* store byte to alternate address space */
752 #ifdef __arch64__
753 static __inline__ void
754 stba(paddr_t loc, int asi, u_char value)
755 {
756 if (PHYS_ASI(asi)) {
757 __asm __volatile("wr %3,%%g0,%%asi; stba %1,[%2]%%asi;"
758 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" :
759 "=&r" (loc) :
760 "r" ((int)(value)), "r" ((unsigned long)(loc)),
761 "r" (asi), "n" (ASI_DCACHE_TAG));
762 } else {
763 __asm __volatile("wr %2,%%g0,%%asi; stba %0,[%1]%%asi" : :
764 "r" ((int)(value)), "r" ((unsigned long)(loc)),
765 "r" (asi));
766 }
767 }
768 #else
769 static __inline__ void
770 stba(paddr_t loc, int asi, u_char value)
771 {
772 register int _loc_hi, _pstate;
773
774 _loc_hi = (((u_int64_t)loc)>>32);
775 if (PHYS_ASI(asi)) {
776 __asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1;"
777 " or %3,%0,%0; wrpr %1,8,%%pstate; stba %2,[%0]%%asi; wrpr %1,0,%%pstate; "
778 " andn %0,0x1f,%1; membar #Sync; stxa %%g0,[%1] %6; membar #Sync" :
779 "=&r" (_loc_hi), "=&r" (_pstate) :
780 "r" ((int)(value)), "r" ((unsigned long)(loc)),
781 "r" (_loc_hi), "r" (asi), "n" (ASI_DCACHE_TAG));
782 } else {
783 __asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; "
784 " or %2,%0,%0; stba %1,[%0]%%asi" : "=&r" (_loc_hi) :
785 "r" ((int)(value)), "r" ((unsigned long)(loc)),
786 "r" (_loc_hi), "r" (asi));
787 }
788 }
789 #endif
790
791 /* store half-word to alternate address space */
792 #ifdef __arch64__
793 static __inline__ void
794 stha(paddr_t loc, int asi, u_short value)
795 {
796 if (PHYS_ASI(asi)) {
797 __asm __volatile("wr %3,%%g0,%%asi; stha %1,[%2]%%asi;"
798 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" :
799 "=&r" (loc) :
800 "r" ((int)(value)), "r" ((unsigned long)(loc)),
801 "r" (asi), "n" (ASI_DCACHE_TAG) : "memory");
802 } else {
803 __asm __volatile("wr %2,%%g0,%%asi; stha %0,[%1]%%asi" : :
804 "r" ((int)(value)), "r" ((unsigned long)(loc)),
805 "r" (asi) : "memory");
806 }
807 }
808 #else
809 static __inline__ void
810 stha(paddr_t loc, int asi, u_short value)
811 {
812 register int _loc_hi, _pstate;
813
814 _loc_hi = (((u_int64_t)loc)>>32);
815 if (PHYS_ASI(asi)) {
816 __asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1;"
817 " or %3,%0,%0; wrpr %1,8,%%pstate; stha %2,[%0]%%asi; wrpr %1,0,%%pstate; "
818 " andn %0,0x1f,%1; membar #Sync; stxa %%g0,[%1] %6; membar #Sync" :
819 "=&r" (_loc_hi), "=&r" (_pstate) :
820 "r" ((int)(value)), "r" ((unsigned long)(loc)),
821 "r" (_loc_hi), "r" (asi),
822 "n" (ASI_DCACHE_TAG) : "memory");
823 } else {
824 __asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; "
825 " or %2,%0,%0; stha %1,[%0]%%asi" : "=&r" (_loc_hi) :
826 "r" ((int)(value)), "r" ((unsigned long)(loc)),
827 "r" (_loc_hi), "r" (asi) : "memory");
828 }
829 }
830 #endif
831
832
833 /* store int to alternate address space */
834 #ifdef __arch64__
835 static __inline__ void
836 sta(paddr_t loc, int asi, u_int value)
837 {
838 if (PHYS_ASI(asi)) {
839 __asm __volatile("wr %3,%%g0,%%asi; sta %1,[%2]%%asi;"
840 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" :
841 "=&r" (loc) :
842 "r" ((int)(value)), "r" ((unsigned long)(loc)),
843 "r" (asi), "n" (ASI_DCACHE_TAG) : "memory");
844 } else {
845 __asm __volatile("wr %2,%%g0,%%asi; sta %0,[%1]%%asi" : :
846 "r" ((int)(value)), "r" ((unsigned long)(loc)),
847 "r" (asi) : "memory");
848 }
849 }
850 #else
851 static __inline__ void
852 sta(paddr_t loc, int asi, u_int value)
853 {
854 register int _loc_hi, _pstate;
855
856 _loc_hi = (((u_int64_t)loc)>>32);
857 if (PHYS_ASI(asi)) {
858 __asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1;"
859 " or %3,%0,%0; wrpr %1,8,%%pstate; sta %2,[%0]%%asi; wrpr %1,0,%%pstate; "
860 " andn %0,0x1f,%1; membar #Sync; stxa %%g0,[%1] %6; membar #Sync" :
861 "=&r" (_loc_hi), "=&r" (_pstate) :
862 "r" ((int)(value)), "r" ((unsigned long)(loc)),
863 "r" (_loc_hi), "r" (asi),
864 "n" (ASI_DCACHE_TAG) : "memory");
865 } else {
866 __asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; "
867 " or %2,%0,%0; sta %1,[%0]%%asi" : "=&r" (_loc_hi) :
868 "r" ((int)(value)), "r" ((unsigned long)(loc)),
869 "r" (_loc_hi), "r" (asi) : "memory");
870 }
871 }
872 #endif
873
874 /* store 64-bit int to alternate address space */
875 #ifdef __arch64__
876 static __inline__ void
877 stda(paddr_t loc, int asi, u_int64_t value)
878 {
879 if (PHYS_ASI(asi)) {
880 __asm __volatile("wr %3,%%g0,%%asi; stda %1,[%2]%%asi;"
881 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" :
882 "=&r" (loc) :
883 "r" ((long long)(value)), "r" ((unsigned long)(loc)),
884 "r" (asi), "n" (ASI_DCACHE_TAG) : "memory");
885 } else {
886 __asm __volatile("wr %2,%%g0,%%asi; stda %0,[%1]%%asi" : :
887 "r" ((long long)(value)), "r" ((unsigned long)(loc)),
888 "r" (asi) : "memory");
889 }
890 }
891 #else
892 static __inline__ void
893 stda(paddr_t loc, int asi, u_int64_t value)
894 {
895 register int _loc_hi, _pstate;
896
897 _loc_hi = (((u_int64_t)loc)>>32);
898 if (PHYS_ASI(asi)) {
899 __asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1; "
900 " or %3,%0,%0; wrpr %1,8,%%pstate; stda %2,[%0]%%asi; wrpr %1,0,%%pstate;"
901 " andn %0,0x1f,%1; membar #Sync; stxa %%g0,[%1] %6; membar #Sync" :
902 "=&r" (_loc_hi), "=&r" (_pstate) :
903 "r" ((long long)(value)), "r" ((unsigned long)(loc)),
904 "r" (_loc_hi), "r" (asi),
905 "n" (ASI_DCACHE_TAG) : "memory");
906 } else {
907 __asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; "
908 " or %2,%0,%0; stda %1,[%0]%%asi" :
909 "=&r" (_loc_hi) :
910 "r" ((long long)(value)), "r" ((unsigned long)(loc)),
911 "r" (_loc_hi), "r" (asi) : "memory");
912 }
913 }
914 #endif
915
916 #ifdef __arch64__
917 /* native store 64-bit int to alternate address space w/64-bit compiler*/
918 static __inline__ void
919 stxa(paddr_t loc, int asi, u_int64_t value)
920 {
921 if (PHYS_ASI(asi)) {
922 __asm __volatile("wr %3,%%g0,%%asi; stxa %1,[%2]%%asi;"
923 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" :
924 "=&r" (asi) :
925 "r" ((unsigned long)(value)),
926 "r" ((unsigned long)(loc)),
927 "r" (asi), "n" (ASI_DCACHE_TAG) : "memory");
928 } else {
929 __asm __volatile("wr %2,%%g0,%%asi; stxa %0,[%1]%%asi" : :
930 "r" ((unsigned long)(value)),
931 "r" ((unsigned long)(loc)), "r" (asi) : "memory");
932 }
933 }
934 #else
935 /* native store 64-bit int to alternate address space w/32-bit compiler*/
936 static __inline__ void
937 stxa(paddr_t loc, int asi, u_int64_t value)
938 {
939 int _stxa_lo, _stxa_hi, _loc_hi;
940
941 _stxa_lo = value;
942 _stxa_hi = ((u_int64_t)value)>>32;
943 _loc_hi = (((u_int64_t)(u_long)loc)>>32);
944
945 if (PHYS_ASI(asi)) {
946 __asm __volatile("wr %7,%%g0,%%asi; sllx %4,32,%1; sllx %6,32,%0; "
947 " or %1,%3,%1; rdpr %%pstate,%2; or %0,%5,%0; wrpr %2,8,%%pstate; "
948 " stxa %1,[%0]%%asi; wrpr %2,0,%%pstate; "
949 " andn %0,0x1f,%1; membar #Sync; stxa %%g0,[%1] %8; membar #Sync" :
950 "=&r" (_loc_hi), "=&r" (_stxa_hi),
951 "=&r" ((int)(_stxa_lo)) :
952 "r" ((int)(_stxa_lo)), "r" ((int)(_stxa_hi)),
953 "r" ((unsigned long)(loc)), "r" (_loc_hi),
954 "r" (asi), "n" (ASI_DCACHE_TAG) : "memory");
955 } else {
956 __asm __volatile("wr %6,%%g0,%%asi; sllx %3,32,%1; sllx %5,32,%0; "
957 " or %1,%2,%1; or %0,%4,%0; stxa %1,[%0]%%asi" :
958 "=&r" (_loc_hi), "=&r" (_stxa_hi) :
959 "r" ((int)(_stxa_lo)), "r" ((int)(_stxa_hi)),
960 "r" ((unsigned long)(loc)), "r" (_loc_hi),
961 "r" (asi) : "memory");
962 }
963 }
964 #endif
965
966 #if 0
967 #ifdef __arch64__
968 /* native store 64-bit int to alternate address space w/64-bit compiler*/
969 static __inline__ u_int64_t
970 casxa(paddr_t loc, int asi, u_int64_t value, u_int64_t oldvalue)
971 {
972 if (PHYS_ASI(asi)) {
973 __asm __volatile("wr %4,%%g0,%%asi; casxa [%3]%%asi,%2,%1;"
974 " andn %3,0x1f,%0; membar #Sync; stxa %%g0,[%0] %5; membar #Sync" :
975 "=&r" (loc), "+r" (value) :
976 "r" ((unsigned long)(oldvalue)),
977 "r" ((unsigned long)(loc)),
978 "r" (asi), "n" (ASI_DCACHE_TAG) : "memory");
979 } else {
980 __asm __volatile("wr %3,%%g0,%%asi; casxa [%1]%%asi,%2,%0" :
981 "+r" (value) :
982 "r" ((unsigned long)(loc)), "r" (oldvalue), "r" (asi) :
983 "memory");
984 }
985 return (value);
986 }
987 #else
988 /* native store 64-bit int to alternate address space w/32-bit compiler*/
989 static __inline__ u_int64_t
990 casxa(paddr_t loc, int asi, u_int64_t value, u_int64_t oldvalue)
991 {
992 int _casxa_lo, _casxa_hi, _loc_hi, _oval_hi;
993
994 _casxa_lo = value;
995 _casxa_hi = ((u_int64_t)value)>>32;
996 _oval_hi = ((u_int64_t)oldvalue)>>32;
997 _loc_hi = (((u_int64_t)(u_long)loc)>>32);
998
999 #ifdef __notyet
1000 /*
1001 * gcc cannot handle this since it thinks it has >10 asm operands.
1002 */
1003 if (PHYS_ASI(asi)) {
1004 __asm __volatile("wr %6,%%g0,%%asi; sllx %1,32,%1; sllx %0,32,%0; "
1005 " sllx %3,32,%3; or %1,%2,%1; rdpr %%pstate,%2; or %0,%4,%0; or %3,%5,%3; "
1006 " wrpr %2,8,%%pstate; casxa [%0]%%asi,%3,%1; wrpr %2,0,%%pstate; "
1007 " andn %0,0x1f,%3; membar #Sync; stxa %%g0,[%3] %7; membar #Sync; "
1008 " sll %1,0,%2; srax %1,32,%1 " :
1009 "+r" (_loc_hi), "+r" (_casxa_hi),
1010 "+r" (_casxa_lo), "+r" (_oval_hi) :
1011 "r" ((unsigned long)(loc)),
1012 "r" ((unsigned int)(oldvalue)),
1013 "r" (asi), "n" (ASI_DCACHE_TAG));
1014 } else {
1015 __asm __volatile("wr %7,%%g0,%%asi; sllx %1,32,%1; sllx %5,32,%0; "
1016 " or %1,%2,%1; sllx %3,32,%2; or %0,%4,%0; or %2,%4,%2; "
1017 " casxa [%0]%%asi,%2,%1; sll %1,0,%2; srax %o1,32,%o1 " :
1018 "=&r" (_loc_hi), "+r" (_casxa_hi), "+r" (_casxa_lo) :
1019 "r" ((int)(_oval_hi)), "r" ((int)(oldvalue)),
1020 "r" ((unsigned long)(loc)), "r" (_loc_hi),
1021 "r" (asi) : "memory");
1022 }
1023 #endif
1024 return (((u_int64_t)_casxa_hi<<32)|(u_int64_t)_casxa_lo);
1025 }
1026 #endif
1027 #endif /* 0 */
1028
1029 #if 0
1030 #ifdef __arch64__
1031 /* load byte from alternate address space */
1032 #define lduba(loc, asi) ({ \
1033 register unsigned int _lduba_v; \
1034 if (PHYS_ASI(asi)) { \
1035 __asm __volatile("wr %3,%%g0,%%asi; " \
1036 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; " \
1037 " lduba [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; " \
1038 " stxa %%g0,[%1] %4; membar #Sync" : \
1039 "=&r" (_lduba_v), "=r" (loc): \
1040 "r" ((unsigned long)(loc)), "r" (asi), "n" (ASI_DCACHE_TAG)); \
1041 } else { \
1042 __asm __volatile("wr %2,%%g0,%%asi; lduba [%1]%%asi,%0" : \
1043 "=r" (_lduba_v) : \
1044 "r" ((unsigned long)(loc)), "r" (asi)); \
1045 } \
1046 _lduba_v; \
1047 })
1048 #else
1049 /* load byte from alternate address space */
1050 #define lduba(loc, asi) ({ \
1051 register unsigned int _lduba_v, _loc_hi, _pstate; \
1052 _loc_hi = (((u_int64_t)loc)>>32); \
1053 if (PHYS_ASI(asi)) { \
1054 __asm __volatile("wr %4,%%g0,%%asi; " \
1055 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; rdpr %%pstate,%1; " \
1056 " sllx %3,32,%0; or %0,%2,%0; wrpr %1,8,%%pstate; " \
1057 " membar #Sync; lduba [%0]%%asi,%0; wrpr %1,0,%%pstate; " \
1058 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" : \
1059 "=&r" (_lduba_v), "=&r" (_pstate) : \
1060 "r" ((unsigned long)(loc)), "r" (_loc_hi), \
1061 "r" (asi), "n" (ASI_DCACHE_TAG)); \
1062 } else { \
1063 __asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; " \
1064 " or %0,%1,%0; lduba [%0]%%asi,%0" : "=&r" (_lduba_v) : \
1065 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
1066 } \
1067 _lduba_v; \
1068 })
1069 #endif
1070
1071 #ifdef __arch64__
1072 /* load half-word from alternate address space */
1073 #define lduha(loc, asi) ({ \
1074 register unsigned int _lduha_v; \
1075 if (PHYS_ASI(asi)) { \
1076 __asm __volatile("wr %3,%%g0,%%asi; " \
1077 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; " \
1078 " lduha [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; " \
1079 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lduha_v), "=r" (loc) : \
1080 "r" ((unsigned long)(loc)), "r" (asi), "n" (ASI_DCACHE_TAG)); \
1081 } else { \
1082 __asm __volatile("wr %2,%%g0,%%asi; lduha [%1]%%asi,%0" : "=r" (_lduha_v) : \
1083 "r" ((unsigned long)(loc)), "r" (asi)); \
1084 } \
1085 _lduha_v; \
1086 })
1087 #else
1088 /* load half-word from alternate address space */
1089 #define lduha(loc, asi) ({ \
1090 register unsigned int _lduha_v, _loc_hi, _pstate; \
1091 _loc_hi = (((u_int64_t)loc)>>32); \
1092 if (PHYS_ASI(asi)) { \
1093 __asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1; " \
1094 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate; sllx %3,32,%0; " \
1095 " or %0,%2,%0; membar #Sync; lduha [%0]%%asi,%0; wrpr %1,0,%%pstate; " \
1096 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" : \
1097 "=&r" (_lduha_v), "=&r" (_pstate) : \
1098 "r" ((unsigned long)(loc)), "r" (_loc_hi), \
1099 "r" (asi), "n" (ASI_DCACHE_TAG)); \
1100 } else { \
1101 __asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; " \
1102 " or %0,%1,%0; lduha [%0]%%asi,%0" : "=&r" (_lduha_v) : \
1103 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
1104 } \
1105 _lduha_v; \
1106 })
1107 #endif
1108
1109 #ifdef __arch64__
1110 /* load unsigned int from alternate address space */
1111 #define lda(loc, asi) ({ \
1112 register unsigned int _lda_v; \
1113 if (PHYS_ASI(asi)) { \
1114 __asm __volatile("wr %3,%%g0,%%asi; " \
1115 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; " \
1116 " lda [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; " \
1117 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=r" (loc) : \
1118 "r" ((unsigned long)(loc)), "r" (asi), "n" (ASI_DCACHE_TAG)); \
1119 } else { \
1120 __asm __volatile("wr %2,%%g0,%%asi; lda [%1]%%asi,%0" : "=r" (_lda_v) : \
1121 "r" ((unsigned long)(loc)), "r" (asi)); \
1122 } \
1123 _lda_v; \
1124 })
1125
1126 /* load signed int from alternate address space */
1127 #define ldswa(loc, asi) ({ \
1128 register int _lda_v; \
1129 if (PHYS_ASI(asi)) { \
1130 __asm __volatile("wr %3,%%g0,%%asi; " \
1131 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; " \
1132 " ldswa [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; " \
1133 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=r" (loc) : \
1134 "r" ((unsigned long)(loc)), "r" (asi), "n" (ASI_DCACHE_TAG)); \
1135 } else { \
1136 __asm __volatile("wr %2,%%g0,%%asi; ldswa [%1]%%asi,%0" : "=r" (_lda_v) : \
1137 "r" ((unsigned long)(loc)), "r" (asi)); \
1138 } \
1139 _lda_v; \
1140 })
1141 #else /* __arch64__ */
1142 /* load unsigned int from alternate address space */
1143 #define lda(loc, asi) ({ \
1144 register unsigned int _lda_v, _loc_hi, _pstate; \
1145 _loc_hi = (((u_int64_t)loc)>>32); \
1146 if (PHYS_ASI(asi)) { \
1147 __asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1;" \
1148 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate; " \
1149 " sllx %3,32,%0; or %0,%2,%0; membar #Sync;lda [%0]%%asi,%0; " \
1150 " wrpr %1,0,%%pstate; andn %2,0x1f,%1; membar #Sync; " \
1151 " stxa %%g0,[%1] %5; membar #Sync" : "=&r" (_lda_v), "=&r" (_pstate) : \
1152 "r" ((unsigned long)(loc)), "r" (_loc_hi), \
1153 "r" (asi), "n" (ASI_DCACHE_TAG)); \
1154 } else { \
1155 __asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; " \
1156 " or %0,%1,%0; lda [%0]%%asi,%0" : "=&r" (_lda_v) : \
1157 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
1158 } \
1159 _lda_v; \
1160 })
1161
1162 /* load signed int from alternate address space */
1163 #define ldswa(loc, asi) ({ \
1164 register int _lda_v, _loc_hi, _pstate; \
1165 _loc_hi = (((u_int64_t)loc)>>32); \
1166 if (PHYS_ASI(asi)) { \
1167 __asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1;" \
1168 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate; sllx %3,32,%0;" \
1169 " or %0,%2,%0; membar #Sync; ldswa [%0]%%asi,%0; wrpr %1,0,%%pstate; " \
1170 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" : \
1171 "=&r" (_lda_v), "=&r" (_pstate) : \
1172 "r" ((unsigned long)(loc)), "r" (_loc_hi), \
1173 "r" (asi), "n" (ASI_DCACHE_TAG)); \
1174 } else { \
1175 __asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; " \
1176 " or %0,%1,%0; ldswa [%0]%%asi,%0" : "=&r" (_lda_v) : \
1177 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
1178 } \
1179 _lda_v; \
1180 })
1181 #endif /* __arch64__ */
1182
1183 #ifdef __arch64__
1184 /* load 64-bit int from alternate address space -- these should never be used */
1185 #define ldda(loc, asi) ({ \
1186 register long long _lda_v; \
1187 if (PHYS_ASI(asi)) { \
1188 __asm __volatile("wr %3,%%g0,%%asi; " \
1189 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; " \
1190 " ldda [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; " \
1191 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=&r" (loc) : \
1192 "r" ((unsigned long)(loc)), "r" (asi), "n" (ASI_DCACHE_TAG)); \
1193 } else { \
1194 __asm __volatile("wr %2,%%g0,%%asi; ldda [%1]%%asi,%0" : "=r" (_lda_v) : \
1195 "r" ((unsigned long)(loc)), "r" (asi)); \
1196 } \
1197 _lda_v; \
1198 })
1199 #else
1200 /* load 64-bit int from alternate address space */
1201 #define ldda(loc, asi) ({ \
1202 register long long _lda_v, _loc_hi, _pstate; \
1203 _loc_hi = (((u_int64_t)loc)>>32); \
1204 if (PHYS_ASI(asi)) { \
1205 __asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1;" \
1206 " andn %2,0x1f,%0; rdpr %%pstate,%1; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate;" \
1207 " sllx %3,32,%0; or %0,%2,%0; membar #Sync; ldda [%0]%%asi,%0; wrpr %1,0,%%pstate; " \
1208 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" : \
1209 "=&r" (_lda_v), "=&r" (_pstate) : \
1210 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi), "n" (ASI_DCACHE_TAG)); \
1211 } else { \
1212 __asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; " \
1213 " or %0,%1,%0; ldda [%0]%%asi,%0" : "=&r" (_lda_v) : \
1214 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
1215 } \
1216 _lda_v; \
1217 })
1218 #endif
1219
1220 #ifdef __arch64__
1221 /* native load 64-bit int from alternate address space w/64-bit compiler*/
1222 #define ldxa(loc, asi) ({ \
1223 register unsigned long _lda_v; \
1224 if (PHYS_ASI(asi)) { \
1225 __asm __volatile("wr %3,%%g0,%%asi; "\
1226 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; " \
1227 " ldxa [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; " \
1228 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=r" (loc) : \
1229 "r" ((unsigned long)(loc)), "r" (asi), "n" (ASI_DCACHE_TAG)); \
1230 } else { \
1231 __asm __volatile("wr %2,%%g0,%%asi; ldxa [%1]%%asi,%0" : "=r" (_lda_v) : \
1232 "r" ((unsigned long)(loc)), "r" (asi)); \
1233 } \
1234 _lda_v; \
1235 })
1236 #else
1237 /* native load 64-bit int from alternate address space w/32-bit compiler*/
1238 #define ldxa(loc, asi) ({ \
1239 register unsigned long _ldxa_lo, _ldxa_hi, _loc_hi; \
1240 _loc_hi = (((u_int64_t)loc)>>32); \
1241 if (PHYS_ASI(asi)) { \
1242 __asm __volatile("wr %4,%%g0,%%asi; " \
1243 " andn %2,0x1f,%0; rdpr %%pstate,%1; stxa %%g0,[%0] %5; " \
1244 " sllx %3,32,%0; wrpr %1,8,%%pstate; or %0,%2,%0; membar #Sync; ldxa [%0]%%asi,%0; " \
1245 " wrpr %1,0,%%pstate; andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync; " \
1246 " srlx %0,32,%1; srl %0,0,%0" : \
1247 "=&r" (_ldxa_lo), "=&r" (_ldxa_hi) : \
1248 "r" ((unsigned long)(loc)), "r" (_loc_hi), \
1249 "r" (asi), "n" (ASI_DCACHE_TAG)); \
1250 } else { \
1251 __asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; " \
1252 " or %0,%2,%0; ldxa [%0]%%asi,%0; srlx %0,32,%1; srl %0,0,%0;" : \
1253 "=&r" (_ldxa_lo), "=&r" (_ldxa_hi) : \
1254 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
1255 } \
1256 ((((int64_t)_ldxa_hi)<<32)|_ldxa_lo); \
1257 })
1258 #endif
1259
1260
1261 /* store byte to alternate address space */
1262 #ifdef __arch64__
1263 #define stba(loc, asi, value) ({ \
1264 if (PHYS_ASI(asi)) { \
1265 __asm __volatile("wr %3,%%g0,%%asi; stba %1,[%2]%%asi;" \
1266 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" : "=&r" (loc) : \
1267 "r" ((int)(value)), "r" ((unsigned long)(loc)), \
1268 "r" (asi), "n" (ASI_DCACHE_TAG)); \
1269 } else { \
1270 __asm __volatile("wr %2,%%g0,%%asi; stba %0,[%1]%%asi" : : \
1271 "r" ((int)(value)), "r" ((unsigned long)(loc)), "r" (asi)); \
1272 } \
1273 })
1274 #else
1275 #define stba(loc, asi, value) ({ \
1276 register int _loc_hi, _pstate; \
1277 _loc_hi = (((u_int64_t)loc)>>32); \
1278 if (PHYS_ASI(asi)) { \
1279 __asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1;" \
1280 " or %3,%0,%0; wrpr %1,8,%%pstate; stba %2,[%0]%%asi; wrpr %1,0,%%pstate; " \
1281 " andn %0,0x1f,%1; membar #Sync; stxa %%g0,[%1] %6; membar #Sync" : \
1282 "=&r" (_loc_hi), "=&r" (_pstate) : \
1283 "r" ((int)(value)), "r" ((unsigned long)(loc)), \
1284 "r" (_loc_hi), "r" (asi), "n" (ASI_DCACHE_TAG)); \
1285 } else { \
1286 __asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; " \
1287 " or %2,%0,%0; stba %1,[%0]%%asi" : "=&r" (_loc_hi) : \
1288 "r" ((int)(value)), "r" ((unsigned long)(loc)), \
1289 "r" (_loc_hi), "r" (asi)); \
1290 } \
1291 })
1292 #endif
1293
1294 /* store half-word to alternate address space */
1295 #ifdef __arch64__
1296 #define stha(loc, asi, value) ({ \
1297 if (PHYS_ASI(asi)) { \
1298 __asm __volatile("wr %3,%%g0,%%asi; stha %1,[%2]%%asi;" \
1299 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" : "=&r" (loc) : \
1300 "r" ((int)(value)), "r" ((unsigned long)(loc)), \
1301 "r" (asi), "n" (ASI_DCACHE_TAG)); \
1302 } else { \
1303 __asm __volatile("wr %2,%%g0,%%asi; stha %0,[%1]%%asi" : : \
1304 "r" ((int)(value)), "r" ((unsigned long)(loc)), "r" (asi)); \
1305 } \
1306 })
1307 #else
1308 #define stha(loc, asi, value) ({ \
1309 register int _loc_hi, _pstate; \
1310 _loc_hi = (((u_int64_t)loc)>>32); \
1311 if (PHYS_ASI(asi)) { \
1312 __asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1;" \
1313 " or %3,%0,%0; wrpr %1,8,%%pstate; stha %2,[%0]%%asi; wrpr %1,0,%%pstate; " \
1314 " andn %0,0x1f,%1; membar #Sync; stxa %%g0,[%1] %6; membar #Sync" : \
1315 "=&r" (_loc_hi), "=&r" (_pstate) : \
1316 "r" ((int)(value)), "r" ((unsigned long)(loc)), \
1317 "r" (_loc_hi), "r" (asi), "n" (ASI_DCACHE_TAG)); \
1318 } else { \
1319 __asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; " \
1320 " or %2,%0,%0; stha %1,[%0]%%asi" : "=&r" (_loc_hi) : \
1321 "r" ((int)(value)), "r" ((unsigned long)(loc)), \
1322 "r" (_loc_hi), "r" (asi)); \
1323 } \
1324 })
1325 #endif
1326
1327 /* store int to alternate address space */
1328 #ifdef __arch64__
1329 #define sta(loc, asi, value) ({ \
1330 if (PHYS_ASI(asi)) { \
1331 __asm __volatile("wr %3,%%g0,%%asi; sta %1,[%2]%%asi;" \
1332 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" : "=&r" (loc) : \
1333 "r" ((int)(value)), "r" ((unsigned long)(loc)), \
1334 "r" (asi), "n" (ASI_DCACHE_TAG)); \
1335 } else { \
1336 __asm __volatile("wr %2,%%g0,%%asi; sta %0,[%1]%%asi" : : \
1337 "r" ((int)(value)), "r" ((unsigned long)(loc)), "r" (asi)); \
1338 } \
1339 })
1340 #else
1341 #define sta(loc, asi, value) ({ \
1342 register int _loc_hi, _pstate; \
1343 _loc_hi = (((u_int64_t)loc)>>32); \
1344 if (PHYS_ASI(asi)) { \
1345 __asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1;" \
1346 " or %3,%0,%0; wrpr %1,8,%%pstate; sta %2,[%0]%%asi; wrpr %1,0,%%pstate; " \
1347 " andn %0,0x1f,%1; membar #Sync; stxa %%g0,[%1] %6; membar #Sync" : \
1348 "=&r" (_loc_hi), "=&r" (_pstate) : \
1349 "r" ((int)(value)), "r" ((unsigned long)(loc)), \
1350 "r" (_loc_hi), "r" (asi), "n" (ASI_DCACHE_TAG)); \
1351 } else { \
1352 __asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; " \
1353 " or %2,%0,%0; sta %1,[%0]%%asi" : "=&r" (_loc_hi) : \
1354 "r" ((int)(value)), "r" ((unsigned long)(loc)), \
1355 "r" (_loc_hi), "r" (asi)); \
1356 } \
1357 })
1358 #endif
1359
1360 /* store 64-bit int to alternate address space */
1361 #ifdef __arch64__
1362 #define stda(loc, asi, value) ({ \
1363 if (PHYS_ASI(asi)) { \
1364 __asm __volatile("wr %3,%%g0,%%asi; stda %1,[%2]%%asi;" \
1365 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" : "=&r" (loc) : \
1366 "r" ((int)(value)), "r" ((unsigned long)(loc)), \
1367 "r" (asi), "n" (ASI_DCACHE_TAG)); \
1368 } else { \
1369 __asm __volatile("wr %2,%%g0,%%asi; stda %0,[%1]%%asi" : : \
1370 "r" ((long long)(value)), "r" ((unsigned long)(loc)), "r" (asi)); \
1371 } \
1372 })
1373 #else
1374 #define stda(loc, asi, value) ({ \
1375 register int _loc_hi, _pstate; \
1376 _loc_hi = (((u_int64_t)loc)>>32); \
1377 if (PHYS_ASI(asi)) { \
1378 __asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1; " \
1379 " or %3,%0,%0; wrpr %1,8,%%pstate; stda %2,[%0]%%asi; wrpr %1,0,%%pstate;" \
1380 " andn %0,0x1f,%1; membar #Sync; stxa %%g0,[%1] %6; membar #Sync" : \
1381 "=&r" (_loc_hi), "=&r" (_pstate) : \
1382 "r" ((long long)(value)), "r" ((unsigned long)(loc)), \
1383 "r" (_loc_hi), "r" (asi), "n" (ASI_DCACHE_TAG)); \
1384 } else { \
1385 __asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; " \
1386 " or %2,%0,%0; stda %1,[%0]%%asi" : "=&r" (_loc_hi) : \
1387 "r" ((long long)(value)), "r" ((unsigned long)(loc)), \
1388 "r" (_loc_hi), "r" (asi)); \
1389 } \
1390 })
1391 #endif
1392
1393 #ifdef __arch64__
1394 /* native store 64-bit int to alternate address space w/64-bit compiler*/
1395 #define stxa(loc, asi, value) ({ \
1396 if (PHYS_ASI(asi)) { \
1397 __asm __volatile("wr %3,%%g0,%%asi; stxa %1,[%2]%%asi;" \
1398 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" : "=&r" (loc) : \
1399 "r" ((int)(value)), "r" ((unsigned long)(loc)), \
1400 "r" (asi), "n" (ASI_DCACHE_TAG)); \
1401 } else { \
1402 __asm __volatile("wr %2,%%g0,%%asi; stxa %0,[%1]%%asi" : : \
1403 "r" ((unsigned long)(value)), "r" ((unsigned long)(loc)), "r" (asi)); \
1404 })
1405 #else
1406 /* native store 64-bit int to alternate address space w/32-bit compiler*/
1407 #define stxa(loc, asi, value) ({ \
1408 int _stxa_lo, _stxa_hi, _loc_hi; \
1409 _stxa_lo = value; _stxa_hi = ((u_int64_t)value)>>32; \
1410 _loc_hi = (((u_int64_t)(u_long)loc)>>32); \
1411 if (PHYS_ASI(asi)) { \
1412 __asm __volatile("wr %7,%%g0,%%asi; sllx %4,32,%1; sllx %6,32,%0; " \
1413 " or %1,%3,%1; rdpr %%pstate,%2; or %0,%5,%0; wrpr %2,8,%%pstate; " \
1414 " stxa %1,[%0]%%asi; wrpr %2,0,%%pstate; " \
1415 " andn %0,0x1f,%1; membar #Sync; stxa %%g0,[%1] %8; membar #Sync": \
1416 "=&r" (_loc_hi), "=&r" (_stxa_hi), "=&r" ((int)(_stxa_lo)): \
1417 "r" ((int)(_stxa_lo)), "r" ((int)(_stxa_hi)), \
1418 "r" ((unsigned long)(loc)), "r" (_loc_hi), \
1419 "r" (asi), "n" (ASI_DCACHE_TAG)); \
1420 } else { \
1421 __asm __volatile("wr %6,%%g0,%%asi; sllx %3,32,%1; sllx %5,32,%0; " \
1422 " or %1,%2,%1; or %0,%4,%0; stxa %1,[%0]%%asi" : \
1423 "=&r" (_loc_hi), "=&r" (_stxa_hi) : \
1424 "r" ((int)(_stxa_lo)), "r" ((int)(_stxa_hi)), \
1425 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
1426 } \
1427 })
1428 #endif
1429
1430
1431 #ifdef __arch64__
1432 /* native store 64-bit int to alternate address space w/64-bit compiler*/
1433 #define casxa(loc, asi, value, ovalue) ({ \
1434 if (PHYS_ASI(asi)) { \
1435 __asm __volatile("wr %5,%%g0,%%asi; casxa [%4]%%asi,%3, %1;" \
1436 " andn %4,0x1f,%0; membar #Sync; stxa %%g0,[%0] %5; membar #Sync" : \
1437 "=&r" (loc), "=&r" (value) : \
1438 "r" ((unsigned long)(value)), "r" ((unsigned long)(ovalue)), \
1439 "r" ((unsigned long)(loc)), \
1440 "r" (asi), "n" (ASI_DCACHE_TAG)); \
1441 } else { \
1442 __asm __volatile("wr %4,%%g0,%%asi; casxa [%3]%%asi,%2,%1" : \
1443 "=&r" (value) : \
1444 "r" ((unsigned long)(value)), "r" ((unsigned long)(ovalue), \
1445 "r" ((unsigned long)(loc)), "r" (asi)); \
1446 })
1447 #else
1448 /* native store 64-bit int to alternate address space w/32-bit compiler*/
1449 #define casxa(loc, asi, value, ovalue) ({ \
1450 int _casxa_lo, _casxa_hi, _oval_lo, _oval_hi, _loc_hi; \
1451 _casxa_lo = value; _casxa_hi = ((u_int64_t)value)>>32; \
1452 _oval_lo = ovalue; _oval_hi = ((u_int64_t)ovalue)>>32; \
1453 _loc_hi = (((u_int64_t)(u_long)loc)>>32); \
1454 if (PHYS_ASI(asi)) { \
1455 __asm __volatile("wr %9,%%g0,%%asi; sllx %4,32,%1; sllx %8,32,%0; " \
1456 " or %1,%3,%1; rdpr %%pstate,%3; or %0,%5,%0; wrpr %3,8,%%pstate; " \
1457 " casxa %1,[%0]%%asi; wrpr %3,0,%%pstate; " \
1458 " andn %0,0x1f,%1; membar #Sync; stxa %%g0,[%1] %8; membar #Sync": \
1459 "=&r" (_casxa_hi), "=&r" ((int)(_casxa_lo)): \
1460 "r" ((int)(_casxa_lo)), "r" ((int)(_casxa_hi)), \
1461 "r" ((int)(_oval_lo)), "r" ((int)(_oval_hi)), \
1462 "r" ((unsigned long)(loc)), "r" (_loc_hi), \
1463 "r" (asi), "n" (ASI_DCACHE_TAG) : \
1464 "r" (loc), "r", (oval_lo) \
1465 } else { \
1466 __asm __volatile("wr %6,%%g0,%%asi; sllx %3,32,%1; sllx %5,32,%0; " \
1467 " or %1,%2,%1; or %0,%4,%0; stxa %1,[%0]%%asi" : \
1468 "=&r" (_loc_hi), "=&r" (_stxa_hi) : \
1469 "r" ((int)(_stxa_lo)), "r" ((int)(_stxa_hi)), \
1470 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
1471 } \
1472 })
1473 #endif
1474 #endif
1475
1476
1477 /* flush address from data cache */
1478 #define flush(loc) ({ \
1479 __asm __volatile("flush %0" : : \
1480 "r" ((unsigned long)(loc))); \
1481 })
1482
1483 /* Flush a D$ line */
1484 #if 0
1485 #define flushline(loc) ({ \
1486 stxa(((paddr_t)loc)&(~0x1f), (ASI_DCACHE_TAG), 0); \
1487 membar_sync(); \
1488 })
1489 #else
1490 #define flushline(loc)
1491 #endif
1492
1493 /* The following two enable or disable the dcache in the LSU control register */
1494 #define dcenable() ({ \
1495 int res; \
1496 __asm __volatile("ldxa [%%g0] %1,%0; or %0,%2,%0; stxa %0,[%%g0] %1; membar #Sync" \
1497 : "r" (res) : "n" (ASI_MCCR), "n" (MCCR_DCACHE_EN)); \
1498 })
1499 #define dcdisable() ({ \
1500 int res; \
1501 __asm __volatile("ldxa [%%g0] %1,%0; andn %0,%2,%0; stxa %0,[%%g0] %1; membar #Sync" \
1502 : "r" (res) : "n" (ASI_MCCR), "n" (MCCR_DCACHE_EN)); \
1503 })
1504
1505 /*
1506 * SPARC V9 memory barrier instructions.
1507 */
1508 /* Make all stores complete before next store */
1509 #define membar_storestore() __asm __volatile("membar #StoreStore" : :)
1510 /* Make all loads complete before next store */
1511 #define membar_loadstore() __asm __volatile("membar #LoadStore" : :)
1512 /* Make all stores complete before next load */
1513 #define membar_storeload() __asm __volatile("membar #StoreLoad" : :)
1514 /* Make all loads complete before next load */
1515 #define membar_loadload() __asm __volatile("membar #LoadLoad" : :)
1516 /* Complete all outstanding memory operations and exceptions */
1517 #define membar_sync() __asm __volatile("membar #Sync" : :)
1518 /* Complete all outstanding memory operations */
1519 #define membar_memissue() __asm __volatile("membar #MemIssue" : :)
1520 /* Complete all outstanding stores before any new loads */
1521 #define membar_lookaside() __asm __volatile("membar #Lookaside" : :)
1522
1523 #ifdef __arch64__
1524 /* read 64-bit %tick register */
1525 #define tick() ({ \
1526 register u_long _tick_tmp; \
1527 __asm __volatile("rdpr %%tick, %0" : "=r" (_tick_tmp) :); \
1528 _tick_tmp; \
1529 })
1530 #else
1531 /* read 64-bit %tick register on 32-bit system */
1532 #define tick() ({ \
1533 register u_int _tick_hi = 0, _tick_lo = 0; \
1534 __asm __volatile("rdpr %%tick, %0; srl %0,0,%1; srlx %0,32,%0 " \
1535 : "=r" (_tick_hi), "=r" (_tick_lo) : ); \
1536 (((u_int64_t)_tick_hi)<<32)|((u_int64_t)_tick_lo); \
1537 })
1538 #endif
1539
1540 extern void next_tick __P((long));
1541 #endif
1542