xref: /illumos-gate/usr/src/uts/sparc/sys/machlock.h (revision 8c69cc8fbe729fa7b091e901c4b50508ccc6bb33)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_MACHLOCK_H
27 #define	_SYS_MACHLOCK_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #ifndef	_ASM
34 
35 #include <sys/types.h>
36 
37 #ifdef _KERNEL
38 
39 extern void	lock_set(lock_t *lp);
40 extern int	lock_try(lock_t *lp);
41 extern int	lock_spin_try(lock_t *lp);
42 extern int	ulock_try(lock_t *lp);
43 extern void	ulock_clear(lock_t *lp);
44 extern void	lock_clear(lock_t *lp);
45 extern void	lock_set_spl(lock_t *lp, int new_pil, ushort_t *old_pil);
46 extern void	lock_clear_splx(lock_t *lp, int s);
47 
48 #endif	/* _KERNEL */
49 
50 #define	LOCK_HELD_VALUE		0xff
51 #define	LOCK_INIT_CLEAR(lp)	(*(lp) = 0)
52 #define	LOCK_INIT_HELD(lp)	(*(lp) = LOCK_HELD_VALUE)
53 #define	LOCK_HELD(lp)		(*(volatile lock_t *)(lp) != 0)
54 
55 typedef	lock_t	disp_lock_t;		/* dispatcher lock type */
56 
57 /*
58  * SPIN_LOCK() macro indicates whether lock is implemented as a spin lock or
59  * an adaptive mutex, depending on what interrupt levels use it.
60  */
61 #define	SPIN_LOCK(pl)	((pl) > ipltospl(LOCK_LEVEL))
62 
63 /*
64  * Macro to control loops which spin on a lock and then check state
65  * periodically.  Its passed an integer, and returns a boolean value
66  * that if true indicates its a good time to get the scheduler lock and
67  * check the state of the current owner of the lock.
68  */
69 #define	LOCK_SAMPLE_INTERVAL(i)	(((i) & 0xff) == 0)
70 
71 /*
72  * Extern for CLOCK_LOCK.
73  */
74 extern	volatile int	hres_lock;
75 
76 #endif	/* _ASM */
77 
78 /*
79  * The definitions of the symbolic interrupt levels:
80  *
81  *   CLOCK_LEVEL =>  The level at which one must be to block the clock.
82  *
83  *   LOCK_LEVEL  =>  The highest level at which one may block (and thus the
84  *                   highest level at which one may acquire adaptive locks)
85  *                   Also the highest level at which one may be preempted.
86  *
87  *   DISP_LEVEL  =>  The level at which one must be to perform dispatcher
88  *                   operations.
89  *
90  * The constraints on the platform:
91  *
92  *  - CLOCK_LEVEL must be less than or equal to LOCK_LEVEL
93  *  - LOCK_LEVEL must be less than DISP_LEVEL
94  *  - DISP_LEVEL should be as close to LOCK_LEVEL as possible
95  *
96  * Note that LOCK_LEVEL and CLOCK_LEVEL have historically always been equal;
97  * changing this relationship is probably possible but not advised.
98  *
99  */
100 #define	CLOCK_LEVEL	10
101 #define	LOCK_LEVEL	10
102 #define	DISP_LEVEL	(LOCK_LEVEL + 1)
103 
104 #define	HIGH_LEVELS	(PIL_MAX - LOCK_LEVEL)
105 
106 #define	PIL_MAX		15
107 
108 /*
109  * The mutex and semaphore code depends on being able to represent a lock
110  * plus owner in a single 32-bit word.  Thus the owner must contain at most
111  * 24 significant bits.  At present only threads, mutexes and semaphores
112  * must be aware of this vile constraint.  Different ISAs may handle this
113  * differently depending on their capabilities (e.g. compare-and-swap)
114  * and limitations (e.g. constraints on alignment and/or KERNELBASE).
115  */
116 #define	PTR24_LSB	5			/* lower bits all zero */
117 #define	PTR24_MSB	(PTR24_LSB + 24)	/* upper bits all one */
118 #define	PTR24_ALIGN	32		/* minimum alignment (1 << lsb) */
119 #define	PTR24_BASE	0xe0000000	/* minimum ptr value (-1 >> (32-msb)) */
120 
121 #ifdef	__cplusplus
122 }
123 #endif
124 
125 #endif	/* _SYS_MACHLOCK_H */
126