xref: /titanic_51/usr/src/uts/sun4v/sys/machthread.h (revision bbaa8b60dd95d714741fc474adad3cf710ef4efd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_MACHTHREAD_H
28 #define	_SYS_MACHTHREAD_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/asi.h>
33 #include <sys/sun4asi.h>
34 #include <sys/machasi.h>
35 #include <sys/bitmap.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #ifdef	_ASM
42 
43 #define	THREAD_REG	%g7		/* pointer to current thread data */
44 
45 /*
46  * CPU_INDEX(r, scr)
47  * Returns cpu id in r.
48  */
49 #define	CPU_INDEX(r, scr)		\
50 	mov	SCRATCHPAD_CPUID, scr;	\
51 	ldxa	[scr]ASI_SCRATCHPAD, r
52 
53 /*
54  * Given a cpu id extract the appropriate word
55  * in the cpuset mask for this cpu id.
56  */
57 #if CPUSET_SIZE > CLONGSIZE
58 #define	CPU_INDEXTOSET(base, index, scr)	\
59 	srl	index, BT_ULSHIFT, scr;		\
60 	and	index, BT_ULMASK, index;	\
61 	sll	scr, CLONGSHIFT, scr;		\
62 	add	base, scr, base
63 #else
64 #define	CPU_INDEXTOSET(base, index, scr)
65 #endif	/* CPUSET_SIZE */
66 
67 
68 /*
69  * Assembly macro to find address of the current CPU.
70  * Used when coming in from a user trap - cannot use THREAD_REG.
71  * Args are destination register and one scratch register.
72  */
73 #define	CPU_ADDR(reg, scr) 		\
74 	.global	cpu;			\
75 	CPU_INDEX(scr, reg);		\
76 	sll	scr, CPTRSHIFT, scr;	\
77 	set	cpu, reg;		\
78 	ldn	[reg + scr], reg
79 
80 #define	CINT64SHIFT	3
81 
82 /*
83  * Assembly macro to find the physical address of the current CPU.
84  * All memory references using VA must be limited to nucleus
85  * memory to avoid any MMU side effect.
86  */
87 #define	CPU_PADDR(reg, scr)				\
88 	.global cpu_pa;					\
89 	CPU_INDEX(scr, reg);				\
90 	sll	scr, CINT64SHIFT, scr;			\
91 	set	cpu_pa, reg;				\
92 	ldx	[reg + scr], reg
93 
94 #endif	/* _ASM */
95 
96 #ifdef	__cplusplus
97 }
98 #endif
99 
100 #endif	/* _SYS_MACHTHREAD_H */
101