xref: /titanic_44/usr/src/uts/common/io/drm/drm_atomic.h (revision 2b4a78020b9c38d1b95e2f3fefa6d6e4be382d1f)
1 /*
2  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 /*
6  * \file drm_atomic.h
7  * Atomic operations used in the DRM which may or may not be provided by the OS.
8  *
9  * \author Eric Anholt <anholt@FreeBSD.org>
10  */
11 
12 /*
13  * Copyright 2004 Eric Anholt
14  * All Rights Reserved.
15  *
16  * Permission is hereby granted, free of charge, to any person obtaining a
17  * copy of this software and associated documentation files (the "Software"),
18  * to deal in the Software without restriction, including without limitation
19  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20  * and/or sell copies of the Software, and to permit persons to whom the
21  * Software is furnished to do so, subject to the following conditions:
22  *
23  * The above copyright notice and this permission notice (including the next
24  * paragraph) shall be included in all copies or substantial portions of the
25  * Software.
26  *
27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
30  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
31  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
32  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33  * OTHER DEALINGS IN THE SOFTWARE.
34  */
35 
36 /* Many of these implementations are rather fake, but good enough. */
37 
38 
39 
40 #ifndef	_SYS_DRM_ATOMIC_H_
41 #define	_SYS_DRM_ATOMIC_H_
42 
43 #pragma ident	"%Z%%M%	%I%	%E% SMI"
44 
45 #ifdef	__cplusplus
46 extern "C" {
47 #endif
48 
49 #include <sys/atomic.h>
50 
51 #ifdef __LINT__
52 #undef inline
53 #define	inline
54 #endif
55 typedef uint32_t	atomic_t;
56 
57 #define	atomic_set(p, v)	(*(p) = (v))
58 #define	atomic_read(p)		(*(p))
59 #define	atomic_inc(p)		atomic_add_int(p, 1)
60 #define	atomic_dec(p)		atomic_dec_uint(p, 1)
61 #define	atomic_add(n, p)	atomic_add_int(p, n)
62 #define	atomic_sub(n, p)	atomic_dec_uint(p, n)
63 #define	atomic_set_int(p, bits)	atomic_or_uint(p, bits)
64 #define	atomic_clear_int(p, bits)	atomic_and_uint(p, ~(bits))
65 #define	atomic_cmpset_int(p, c, n) \
66 	((c == atomic_cas_uint(p, c, n)) ? 1 : 0)
67 
68 #define	set_bit(b, p) \
69 	atomic_set_int(((volatile uint_t *)(void *)p) + (b >> 5), \
70 	1 << (b & 0x1f))
71 
72 #define	clear_bit(b, p) \
73 	atomic_clear_int(((volatile uint_t *)(void *)p) + (b >> 5), \
74 	1 << (b & 0x1f))
75 
76 #define	test_bit(b, p) \
77 	(((volatile uint_t *)(void *)p)[b >> 5] & (1 << (b & 0x1f)))
78 
79 /*
80  * Note: this routine doesn't return old value. It return
81  * 0 when succeeds, or -1 when fails.
82  */
83 #ifdef _LP64
84 #define	test_and_set_bit(b, p) \
85 	atomic_set_long_excl(((ulong_t *)(void *)p) + (b >> 6), (b & 0x3f))
86 #else
87 #define	test_and_set_bit(b, p) \
88 	atomic_set_long_excl(((ulong_t *)(void *)p) + (b >> 5), (b & 0x1f))
89 #endif
90 
91 #ifdef	__cplusplus
92 }
93 #endif
94 
95 #endif /* _SYS_DRM_ATOMIC_H_ */
96