drm_linux.h revision 1450
1450N/A/*
1450N/A * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
1450N/A *
1450N/A * Permission is hereby granted, free of charge, to any person obtaining a
1450N/A * copy of this software and associated documentation files (the "Software"),
1450N/A * to deal in the Software without restriction, including without limitation
1450N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1450N/A * and/or sell copies of the Software, and to permit persons to whom the
1450N/A * Software is furnished to do so, subject to the following conditions:
1450N/A *
1450N/A * The above copyright notice and this permission notice (including the next
1450N/A * paragraph) shall be included in all copies or substantial portions of the
1450N/A * Software.
1450N/A *
1450N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1450N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1450N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1450N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1450N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1450N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1450N/A * DEALINGS IN THE SOFTWARE.
1450N/A */
1450N/A
1450N/A/*
1450N/A * Copyright (c) 2012, 2012 Intel Corporation. All rights reserved.
1450N/A */
1450N/A
1450N/A#ifndef __DRM_LINUX_H__
1450N/A#define __DRM_LINUX_H__
1450N/A
1450N/A#include <sys/types.h>
1450N/A#include <sys/byteorder.h>
1450N/A#include "drm_atomic.h"
1450N/A
1450N/A#define DRM_MEM_CACHED 0
1450N/A#define DRM_MEM_UNCACHED 1
1450N/A#define DRM_MEM_WC 2
1450N/A
1450N/A#ifndef min
1450N/A#define min(a, b) (((a) < (b)) ? (a) : (b))
1450N/A#endif
1450N/A
1450N/A#ifndef max
1450N/A#define max(a, b) (((a) > (b)) ? (a) : (b))
1450N/A#endif
1450N/A
1450N/A#define clamp_int64_t(val) \
1450N/A val = min((int64_t)INT_MAX, val); \
1450N/A val = max((int64_t)INT_MIN, val);
1450N/A
1450N/A#define ioremap_wc(base,size) drm_sun_ioremap((base), (size), DRM_MEM_WC)
1450N/A#define ioremap(base, size) drm_sun_ioremap((base), (size), DRM_MEM_UNCACHED)
1450N/A#define iounmap(addr) drm_sun_iounmap((addr))
1450N/A
1450N/A#define spinlock_t kmutex_t
1450N/A#define spin_lock_init(l) mutex_init((l), NULL, MUTEX_DRIVER, NULL);
1450N/A#define spin_lock(l) mutex_enter(l)
1450N/A#define spin_unlock(u) mutex_exit(u)
1450N/A#define spin_lock_irq(l) mutex_enter(l)
1450N/A#define spin_unlock_irq(u) mutex_exit(u)
1450N/A#ifdef __lint
1450N/A/*
1450N/A * The following is to keep lint happy when it encouters the use of 'flag'.
1450N/A * On Linux, this allows a local variable to be used to retain context,
1450N/A * but is unused on Solaris. Rather than trying to place LINTED
1450N/A * directives in the source, we actually consue the flag for lint here.
1450N/A */
1450N/A#define spin_lock_irqsave(l, flag) flag = 0; mutex_enter(l)
1450N/A#define spin_unlock_irqrestore(u, flag) flag &= flag; mutex_exit(u)
1450N/A#else
1450N/A#define spin_lock_irqsave(l, flag) mutex_enter(l)
1450N/A#define spin_unlock_irqrestore(u, flag) mutex_exit(u)
1450N/A#endif
1450N/A
1450N/A#define mutex_lock(l) mutex_enter(l)
1450N/A#define mutex_unlock(u) mutex_exit(u)
1450N/A#define mutex_is_locked(l) mutex_owned(l)
1450N/A
1450N/A#define assert_spin_locked(l) ASSERT(MUTEX_HELD(l))
1450N/A
1450N/A#define kmalloc kmem_alloc
1450N/A#define kzalloc kmem_zalloc
1450N/A#define kcalloc(x, y, z) kzalloc((x)*(y), z)
1450N/A#define kfree kmem_free
1450N/A
1450N/A#define do_gettimeofday (void) uniqtime
1450N/A#define msleep_interruptible(s) DRM_UDELAY(s)
1450N/A#define timeval_to_ns(tvp) TICK_TO_NSEC(TIMEVAL_TO_TICK(tvp))
1450N/A#define ns_to_timeval(nsec, tvp) TICK_TO_TIMEVAL(NSEC_TO_TICK(nsec), tvp)
1450N/A
1450N/A#define GFP_KERNEL KM_SLEEP
1450N/A#define GFP_ATOMIC KM_SLEEP
1450N/A
1450N/A#define KHZ2PICOS(a) (1000000000UL/(a))
1450N/A
1450N/A#define udelay drv_usecwait
1450N/A#define mdelay(x) udelay((x) * 1000)
1450N/A#define msleep(x) mdelay((x))
1450N/A#define msecs_to_jiffies(x) drv_usectohz((x) * 1000)
1450N/A#define jiffies_to_msecs(x) drv_hztousec(x) / 1000
1450N/A#define time_after(a,b) ((long)(b) - (long)(a) < 0)
1450N/A#define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
1450N/A#define time_before_eq(a,b) time_after_eq(b,a)
1450N/A#define time_in_range(a,b,c) \
1450N/A (time_after_eq(a,b) && \
1450N/A time_before_eq(a,c))
1450N/A
1450N/A#define jiffies ddi_get_lbolt()
1450N/A
1450N/A#ifdef _BIG_ENDIAN
1450N/A#define cpu_to_le16(x) LE_16(x)
1450N/A#define le16_to_cpu(x) LE_16(x)
1450N/A#else
1450N/A#define cpu_to_le16(x) (x)
1450N/A#define le16_to_cpu(x) (x)
1450N/A#endif
1450N/A
1450N/A#define swap(a, b) \
1450N/A do { int tmp = (a); (a) = (b); (b) = tmp; } while (__lintzero)
1450N/A
1450N/A#define abs(x) ((x < 0) ? -x : x)
1450N/A
1450N/A#define div_u64(x, y) ((unsigned long long)(x))/((unsigned long long)(y)) /* XXX FIXME */
1450N/A#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
1450N/A
1450N/A#define put_user(val,ptr) DRM_COPY_TO_USER(ptr,(&val),sizeof(val))
1450N/A#define get_user(x,ptr) DRM_COPY_FROM_USER((&x),ptr,sizeof(x))
1450N/A#define copy_to_user DRM_COPY_TO_USER
1450N/A#define copy_from_user DRM_COPY_FROM_USER
1450N/A#define unlikely(a) (a)
1450N/A
1450N/A#define AGP_USER_TYPES (1 << 16)
1450N/A#define AGP_USER_MEMORY (AGP_USER_TYPES)
1450N/A#define AGP_USER_CACHED_MEMORY (AGP_USER_TYPES + 1)
1450N/A
1450N/A#define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
1450N/A
1450N/A#define page_to_phys(x) *(uint32_t *)(uintptr_t)(x)
1450N/A#define in_dbg_master() 0
1450N/A
1450N/A#define BITS_PER_BYTE 8
1450N/A#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
1450N/A#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
1450N/A#define POS_DIV_ROUND_CLOSEST(x, d) ((x + (d / 2)) / d)
1450N/A#define POS_DIV_ROUND_UP_ULL(x, d) DIV_ROUND_UP(x,d)
1450N/A
1450N/Atypedef unsigned long dma_addr_t;
1450N/Atypedef uint64_t u64;
1450N/Atypedef int64_t s64;
1450N/Atypedef uint32_t u32;
1450N/Atypedef int32_t s32;
1450N/Atypedef uint16_t u16;
1450N/Atypedef uint8_t u8;
1450N/Atypedef uint_t irqreturn_t;
1450N/A
1450N/Atypedef int bool;
1450N/A
1450N/A#define true (1)
1450N/A#define false (0)
1450N/A
1450N/A#define __init
1450N/A#define __exit
1450N/A#define __iomem
1450N/A
1450N/A#ifdef _ILP32
1450N/Atypedef u32 resource_size_t;
1450N/A#else /* _LP64 */
1450N/Atypedef u64 resource_size_t;
1450N/A#endif
1450N/A
1450N/Atypedef struct kref {
1450N/A atomic_t refcount;
1450N/A} kref_t;
1450N/A
1450N/Aextern void kref_init(struct kref *kref);
1450N/Aextern void kref_get(struct kref *kref);
1450N/Aextern void kref_put(struct kref *kref, void (*release)(struct kref *kref));
1450N/A
1450N/Aextern unsigned int hweight16(unsigned int w);
1450N/A
1450N/Aextern long IS_ERR(const void *ptr);
1450N/A#define IS_ERR_OR_NULL(ptr) (!ptr || IS_ERR(ptr))
1450N/A
1450N/A#ifdef __lint
1450N/A/*
1450N/A * The actual code for _wait_for() causes Solaris lint2 to fail, though
1450N/A * by all appearances, the code actually works (may try and peek at
1450N/A * the compiled code to understand why). So to get around the problem,
1450N/A * we create a special lint version for _wait_for().
1450N/A */
1450N/A#define _wait_for(COND, MS, W) (! (COND))
1450N/A#else /* !__lint */
1450N/A#define _wait_for(COND, MS, W) ({ \
1450N/A unsigned long timeout__ = jiffies + msecs_to_jiffies(MS); \
1450N/A int ret__ = 0; \
1450N/A while (! (COND)) { \
1450N/A if (time_after(jiffies, timeout__)) { \
1450N/A ret__ = -ETIMEDOUT; \
1450N/A break; \
1450N/A } \
1450N/A if (W) udelay(W); \
1450N/A } \
1450N/A ret__; \
1450N/A})
1450N/A#endif /* __lint */
1450N/A
1450N/A#define wait_for(COND, MS) _wait_for(COND, MS, 1)
1450N/A#define wait_for_atomic(COND, MS) _wait_for(COND, MS, 0)
1450N/A
1450N/A#endif /* __DRM_LINUX_H__ */