cg149915 | 66310b5 | 2007-10-29 22:02:09 -0700 | [diff] [blame] | 1 | /* |
miao chen - Sun Microsystems - Beijing China | d023107 | 2009-02-17 16:22:10 +0800 | [diff] [blame] | 2 | * Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
cg149915 | 66310b5 | 2007-10-29 22:02:09 -0700 | [diff] [blame] | 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 |
miao chen - Sun Microsystems - Beijing China | 0035d21 | 2009-12-05 13:25:40 +0800 | [diff] [blame] | 14 | * Copyright (c) 2009, Intel Corporation. |
cg149915 | 66310b5 | 2007-10-29 22:02:09 -0700 | [diff] [blame] | 15 | * All Rights Reserved. |
| 16 | * |
| 17 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 18 | * copy of this software and associated documentation files (the "Software"), |
| 19 | * to deal in the Software without restriction, including without limitation |
| 20 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 21 | * and/or sell copies of the Software, and to permit persons to whom the |
| 22 | * Software is furnished to do so, subject to the following conditions: |
| 23 | * |
| 24 | * The above copyright notice and this permission notice (including the next |
| 25 | * paragraph) shall be included in all copies or substantial portions of the |
| 26 | * Software. |
| 27 | * |
| 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 29 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 30 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 31 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 32 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 33 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 34 | * OTHER DEALINGS IN THE SOFTWARE. |
| 35 | */ |
| 36 | |
| 37 | /* Many of these implementations are rather fake, but good enough. */ |
| 38 | |
| 39 | |
| 40 | |
| 41 | #ifndef _SYS_DRM_ATOMIC_H_ |
| 42 | #define _SYS_DRM_ATOMIC_H_ |
| 43 | |
cg149915 | 66310b5 | 2007-10-29 22:02:09 -0700 | [diff] [blame] | 44 | #ifdef __cplusplus |
| 45 | extern "C" { |
| 46 | #endif |
| 47 | |
| 48 | #include <sys/atomic.h> |
| 49 | |
| 50 | #ifdef __LINT__ |
| 51 | #undef inline |
| 52 | #define inline |
| 53 | #endif |
| 54 | typedef uint32_t atomic_t; |
| 55 | |
| 56 | #define atomic_set(p, v) (*(p) = (v)) |
| 57 | #define atomic_read(p) (*(p)) |
Josef 'Jeff' Sipek | 1a5e258 | 2014-08-08 10:50:14 -0400 | [diff] [blame] | 58 | #define atomic_inc(p) atomic_inc_uint(p) |
miao chen - Sun Microsystems - Beijing China | d023107 | 2009-02-17 16:22:10 +0800 | [diff] [blame] | 59 | #define atomic_dec(p) atomic_dec_uint(p) |
cg149915 | 66310b5 | 2007-10-29 22:02:09 -0700 | [diff] [blame] | 60 | #define atomic_add(n, p) atomic_add_int(p, n) |
miao chen - Sun Microsystems - Beijing China | 0035d21 | 2009-12-05 13:25:40 +0800 | [diff] [blame] | 61 | #define atomic_sub(n, p) atomic_add_int(p, -n) |
cg149915 | d0538f6 | 2008-01-09 19:45:15 -0800 | [diff] [blame] | 62 | #define atomic_set_int(p, bits) atomic_or_uint(p, bits) |
| 63 | #define atomic_clear_int(p, bits) atomic_and_uint(p, ~(bits)) |
cg149915 | 66310b5 | 2007-10-29 22:02:09 -0700 | [diff] [blame] | 64 | #define atomic_cmpset_int(p, c, n) \ |
| 65 | ((c == atomic_cas_uint(p, c, n)) ? 1 : 0) |
| 66 | |
cg149915 | d0538f6 | 2008-01-09 19:45:15 -0800 | [diff] [blame] | 67 | #define set_bit(b, p) \ |
| 68 | atomic_set_int(((volatile uint_t *)(void *)p) + (b >> 5), \ |
| 69 | 1 << (b & 0x1f)) |
cg149915 | 66310b5 | 2007-10-29 22:02:09 -0700 | [diff] [blame] | 70 | |
| 71 | #define clear_bit(b, p) \ |
cg149915 | d0538f6 | 2008-01-09 19:45:15 -0800 | [diff] [blame] | 72 | atomic_clear_int(((volatile uint_t *)(void *)p) + (b >> 5), \ |
| 73 | 1 << (b & 0x1f)) |
cg149915 | 66310b5 | 2007-10-29 22:02:09 -0700 | [diff] [blame] | 74 | |
| 75 | #define test_bit(b, p) \ |
cg149915 | d0538f6 | 2008-01-09 19:45:15 -0800 | [diff] [blame] | 76 | (((volatile uint_t *)(void *)p)[b >> 5] & (1 << (b & 0x1f))) |
| 77 | |
| 78 | /* |
| 79 | * Note: this routine doesn't return old value. It return |
| 80 | * 0 when succeeds, or -1 when fails. |
| 81 | */ |
| 82 | #ifdef _LP64 |
| 83 | #define test_and_set_bit(b, p) \ |
| 84 | atomic_set_long_excl(((ulong_t *)(void *)p) + (b >> 6), (b & 0x3f)) |
| 85 | #else |
| 86 | #define test_and_set_bit(b, p) \ |
| 87 | atomic_set_long_excl(((ulong_t *)(void *)p) + (b >> 5), (b & 0x1f)) |
| 88 | #endif |
cg149915 | 66310b5 | 2007-10-29 22:02:09 -0700 | [diff] [blame] | 89 | |
| 90 | #ifdef __cplusplus |
| 91 | } |
| 92 | #endif |
| 93 | |
| 94 | #endif /* _SYS_DRM_ATOMIC_H_ */ |