166310b5bScg149915 /* 2d0231070Smiao chen - Sun Microsystems - Beijing China * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 366310b5bScg149915 * Use is subject to license terms. 466310b5bScg149915 */ 566310b5bScg149915 /* 666310b5bScg149915 * \file drm_atomic.h 766310b5bScg149915 * Atomic operations used in the DRM which may or may not be provided by the OS. 866310b5bScg149915 * 966310b5bScg149915 * \author Eric Anholt <anholt@FreeBSD.org> 1066310b5bScg149915 */ 1166310b5bScg149915 1266310b5bScg149915 /* 1366310b5bScg149915 * Copyright 2004 Eric Anholt 140035d21cSmiao chen - Sun Microsystems - Beijing China * Copyright (c) 2009, Intel Corporation. 1566310b5bScg149915 * All Rights Reserved. 1666310b5bScg149915 * 1766310b5bScg149915 * Permission is hereby granted, free of charge, to any person obtaining a 1866310b5bScg149915 * copy of this software and associated documentation files (the "Software"), 1966310b5bScg149915 * to deal in the Software without restriction, including without limitation 2066310b5bScg149915 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 2166310b5bScg149915 * and/or sell copies of the Software, and to permit persons to whom the 2266310b5bScg149915 * Software is furnished to do so, subject to the following conditions: 2366310b5bScg149915 * 2466310b5bScg149915 * The above copyright notice and this permission notice (including the next 2566310b5bScg149915 * paragraph) shall be included in all copies or substantial portions of the 2666310b5bScg149915 * Software. 2766310b5bScg149915 * 2866310b5bScg149915 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2966310b5bScg149915 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 3066310b5bScg149915 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 3166310b5bScg149915 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 3266310b5bScg149915 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 3366310b5bScg149915 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 3466310b5bScg149915 * OTHER DEALINGS IN THE SOFTWARE. 3566310b5bScg149915 */ 3666310b5bScg149915 3766310b5bScg149915 /* Many of these implementations are rather fake, but good enough. */ 3866310b5bScg149915 3966310b5bScg149915 4066310b5bScg149915 4166310b5bScg149915 #ifndef _SYS_DRM_ATOMIC_H_ 4266310b5bScg149915 #define _SYS_DRM_ATOMIC_H_ 4366310b5bScg149915 4466310b5bScg149915 #ifdef __cplusplus 4566310b5bScg149915 extern "C" { 4666310b5bScg149915 #endif 4766310b5bScg149915 4866310b5bScg149915 #include <sys/atomic.h> 4966310b5bScg149915 5066310b5bScg149915 #ifdef __LINT__ 5166310b5bScg149915 #undef inline 5266310b5bScg149915 #define inline 5366310b5bScg149915 #endif 5466310b5bScg149915 typedef uint32_t atomic_t; 5566310b5bScg149915 5666310b5bScg149915 #define atomic_set(p, v) (*(p) = (v)) 5766310b5bScg149915 #define atomic_read(p) (*(p)) 58*1a5e258fSJosef 'Jeff' Sipek #define atomic_inc(p) atomic_inc_uint(p) 59d0231070Smiao chen - Sun Microsystems - Beijing China #define atomic_dec(p) atomic_dec_uint(p) 6066310b5bScg149915 #define atomic_add(n, p) atomic_add_int(p, n) 610035d21cSmiao chen - Sun Microsystems - Beijing China #define atomic_sub(n, p) atomic_add_int(p, -n) 62d0538f66Scg149915 #define atomic_set_int(p, bits) atomic_or_uint(p, bits) 63d0538f66Scg149915 #define atomic_clear_int(p, bits) atomic_and_uint(p, ~(bits)) 6466310b5bScg149915 #define atomic_cmpset_int(p, c, n) \ 6566310b5bScg149915 ((c == atomic_cas_uint(p, c, n)) ? 1 : 0) 6666310b5bScg149915 6766310b5bScg149915 #define set_bit(b, p) \ 68d0538f66Scg149915 atomic_set_int(((volatile uint_t *)(void *)p) + (b >> 5), \ 69d0538f66Scg149915 1 << (b & 0x1f)) 7066310b5bScg149915 7166310b5bScg149915 #define clear_bit(b, p) \ 72d0538f66Scg149915 atomic_clear_int(((volatile uint_t *)(void *)p) + (b >> 5), \ 73d0538f66Scg149915 1 << (b & 0x1f)) 7466310b5bScg149915 7566310b5bScg149915 #define test_bit(b, p) \ 76d0538f66Scg149915 (((volatile uint_t *)(void *)p)[b >> 5] & (1 << (b & 0x1f))) 77d0538f66Scg149915 78d0538f66Scg149915 /* 79d0538f66Scg149915 * Note: this routine doesn't return old value. It return 80d0538f66Scg149915 * 0 when succeeds, or -1 when fails. 81d0538f66Scg149915 */ 82d0538f66Scg149915 #ifdef _LP64 83d0538f66Scg149915 #define test_and_set_bit(b, p) \ 84d0538f66Scg149915 atomic_set_long_excl(((ulong_t *)(void *)p) + (b >> 6), (b & 0x3f)) 85d0538f66Scg149915 #else 86d0538f66Scg149915 #define test_and_set_bit(b, p) \ 87d0538f66Scg149915 atomic_set_long_excl(((ulong_t *)(void *)p) + (b >> 5), (b & 0x1f)) 88d0538f66Scg149915 #endif 8966310b5bScg149915 9066310b5bScg149915 #ifdef __cplusplus 9166310b5bScg149915 } 9266310b5bScg149915 #endif 9366310b5bScg149915 9466310b5bScg149915 #endif /* _SYS_DRM_ATOMIC_H_ */ 95