66310b5b6be388602e7aa8639a404efd2ddb5687cg/*
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
66310b5b6be388602e7aa8639a404efd2ddb5687cg * Use is subject to license terms.
66310b5b6be388602e7aa8639a404efd2ddb5687cg */
66310b5b6be388602e7aa8639a404efd2ddb5687cg/*
66310b5b6be388602e7aa8639a404efd2ddb5687cg * \file drm_atomic.h
66310b5b6be388602e7aa8639a404efd2ddb5687cg * Atomic operations used in the DRM which may or may not be provided by the OS.
66310b5b6be388602e7aa8639a404efd2ddb5687cg *
66310b5b6be388602e7aa8639a404efd2ddb5687cg * \author Eric Anholt <anholt@FreeBSD.org>
66310b5b6be388602e7aa8639a404efd2ddb5687cg */
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg/*
66310b5b6be388602e7aa8639a404efd2ddb5687cg * Copyright 2004 Eric Anholt
0035d21c77a24d02faf34c10aabc120ca692efb5miao chen - Sun Microsystems - Beijing China * Copyright (c) 2009, Intel Corporation.
66310b5b6be388602e7aa8639a404efd2ddb5687cg * All Rights Reserved.
66310b5b6be388602e7aa8639a404efd2ddb5687cg *
66310b5b6be388602e7aa8639a404efd2ddb5687cg * Permission is hereby granted, free of charge, to any person obtaining a
66310b5b6be388602e7aa8639a404efd2ddb5687cg * copy of this software and associated documentation files (the "Software"),
66310b5b6be388602e7aa8639a404efd2ddb5687cg * to deal in the Software without restriction, including without limitation
66310b5b6be388602e7aa8639a404efd2ddb5687cg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
66310b5b6be388602e7aa8639a404efd2ddb5687cg * and/or sell copies of the Software, and to permit persons to whom the
66310b5b6be388602e7aa8639a404efd2ddb5687cg * Software is furnished to do so, subject to the following conditions:
66310b5b6be388602e7aa8639a404efd2ddb5687cg *
66310b5b6be388602e7aa8639a404efd2ddb5687cg * The above copyright notice and this permission notice (including the next
66310b5b6be388602e7aa8639a404efd2ddb5687cg * paragraph) shall be included in all copies or substantial portions of the
66310b5b6be388602e7aa8639a404efd2ddb5687cg * Software.
66310b5b6be388602e7aa8639a404efd2ddb5687cg *
66310b5b6be388602e7aa8639a404efd2ddb5687cg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
66310b5b6be388602e7aa8639a404efd2ddb5687cg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
66310b5b6be388602e7aa8639a404efd2ddb5687cg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
66310b5b6be388602e7aa8639a404efd2ddb5687cg * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
66310b5b6be388602e7aa8639a404efd2ddb5687cg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
66310b5b6be388602e7aa8639a404efd2ddb5687cg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
66310b5b6be388602e7aa8639a404efd2ddb5687cg * OTHER DEALINGS IN THE SOFTWARE.
66310b5b6be388602e7aa8639a404efd2ddb5687cg */
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg/* Many of these implementations are rather fake, but good enough. */
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg#ifndef _SYS_DRM_ATOMIC_H_
66310b5b6be388602e7aa8639a404efd2ddb5687cg#define _SYS_DRM_ATOMIC_H_
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg#ifdef __cplusplus
66310b5b6be388602e7aa8639a404efd2ddb5687cgextern "C" {
66310b5b6be388602e7aa8639a404efd2ddb5687cg#endif
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg#include <sys/atomic.h>
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg#ifdef __LINT__
66310b5b6be388602e7aa8639a404efd2ddb5687cg#undef inline
66310b5b6be388602e7aa8639a404efd2ddb5687cg#define inline
66310b5b6be388602e7aa8639a404efd2ddb5687cg#endif
66310b5b6be388602e7aa8639a404efd2ddb5687cgtypedef uint32_t atomic_t;
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg#define atomic_set(p, v) (*(p) = (v))
66310b5b6be388602e7aa8639a404efd2ddb5687cg#define atomic_read(p) (*(p))
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek#define atomic_inc(p) atomic_inc_uint(p)
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China#define atomic_dec(p) atomic_dec_uint(p)
66310b5b6be388602e7aa8639a404efd2ddb5687cg#define atomic_add(n, p) atomic_add_int(p, n)
0035d21c77a24d02faf34c10aabc120ca692efb5miao chen - Sun Microsystems - Beijing China#define atomic_sub(n, p) atomic_add_int(p, -n)
d0538f66491267879b7418b21ad78e3dcc2dcc83cg#define atomic_set_int(p, bits) atomic_or_uint(p, bits)
d0538f66491267879b7418b21ad78e3dcc2dcc83cg#define atomic_clear_int(p, bits) atomic_and_uint(p, ~(bits))
66310b5b6be388602e7aa8639a404efd2ddb5687cg#define atomic_cmpset_int(p, c, n) \
66310b5b6be388602e7aa8639a404efd2ddb5687cg ((c == atomic_cas_uint(p, c, n)) ? 1 : 0)
66310b5b6be388602e7aa8639a404efd2ddb5687cg
d0538f66491267879b7418b21ad78e3dcc2dcc83cg#define set_bit(b, p) \
d0538f66491267879b7418b21ad78e3dcc2dcc83cg atomic_set_int(((volatile uint_t *)(void *)p) + (b >> 5), \
d0538f66491267879b7418b21ad78e3dcc2dcc83cg 1 << (b & 0x1f))
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg#define clear_bit(b, p) \
d0538f66491267879b7418b21ad78e3dcc2dcc83cg atomic_clear_int(((volatile uint_t *)(void *)p) + (b >> 5), \
d0538f66491267879b7418b21ad78e3dcc2dcc83cg 1 << (b & 0x1f))
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg#define test_bit(b, p) \
d0538f66491267879b7418b21ad78e3dcc2dcc83cg (((volatile uint_t *)(void *)p)[b >> 5] & (1 << (b & 0x1f)))
d0538f66491267879b7418b21ad78e3dcc2dcc83cg
d0538f66491267879b7418b21ad78e3dcc2dcc83cg/*
d0538f66491267879b7418b21ad78e3dcc2dcc83cg * Note: this routine doesn't return old value. It return
d0538f66491267879b7418b21ad78e3dcc2dcc83cg * 0 when succeeds, or -1 when fails.
d0538f66491267879b7418b21ad78e3dcc2dcc83cg */
d0538f66491267879b7418b21ad78e3dcc2dcc83cg#ifdef _LP64
d0538f66491267879b7418b21ad78e3dcc2dcc83cg#define test_and_set_bit(b, p) \
d0538f66491267879b7418b21ad78e3dcc2dcc83cg atomic_set_long_excl(((ulong_t *)(void *)p) + (b >> 6), (b & 0x3f))
d0538f66491267879b7418b21ad78e3dcc2dcc83cg#else
d0538f66491267879b7418b21ad78e3dcc2dcc83cg#define test_and_set_bit(b, p) \
d0538f66491267879b7418b21ad78e3dcc2dcc83cg atomic_set_long_excl(((ulong_t *)(void *)p) + (b >> 5), (b & 0x1f))
d0538f66491267879b7418b21ad78e3dcc2dcc83cg#endif
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg#ifdef __cplusplus
66310b5b6be388602e7aa8639a404efd2ddb5687cg}
66310b5b6be388602e7aa8639a404efd2ddb5687cg#endif
66310b5b6be388602e7aa8639a404efd2ddb5687cg
66310b5b6be388602e7aa8639a404efd2ddb5687cg#endif /* _SYS_DRM_ATOMIC_H_ */