Remove DRM_ERR OS macro.
[platform/upstream/libdrm.git] / linux-core / drm_os_linux.h
1 /**
2  * \file drm_os_linux.h
3  * OS abstraction macros.
4  */
5
6 #include <linux/interrupt.h>    /* For task queue support */
7 #include <linux/delay.h>
8
9 /** File pointer type */
10 #define DRMFILE                         struct file *
11 /** Ioctl arguments */
12 #define DRM_IOCTL_ARGS                  struct inode *inode, struct file *filp, unsigned int cmd, unsigned long data
13 /** Current process ID */
14 #define DRM_CURRENTPID                  current->pid
15 #define DRM_SUSER(p)                    capable(CAP_SYS_ADMIN)
16 #define DRM_UDELAY(d)                   udelay(d)
17 #if LINUX_VERSION_CODE <= 0x020608      /* KERNEL_VERSION(2,6,8) */
18 #ifndef __iomem
19 #define __iomem
20 #endif
21 /** Read a byte from a MMIO region */
22 #define DRM_READ8(map, offset)          readb(((void __iomem *)(map)->handle) + (offset))
23 /** Read a word from a MMIO region */
24 #define DRM_READ16(map, offset)         readw(((void __iomem *)(map)->handle) + (offset))
25 /** Read a dword from a MMIO region */
26 #define DRM_READ32(map, offset)         readl(((void __iomem *)(map)->handle) + (offset))
27 /** Write a byte into a MMIO region */
28 #define DRM_WRITE8(map, offset, val)    writeb(val, ((void __iomem *)(map)->handle) + (offset))
29 /** Write a word into a MMIO region */
30 #define DRM_WRITE16(map, offset, val)   writew(val, ((void __iomem *)(map)->handle) + (offset))
31 /** Write a dword into a MMIO region */
32 #define DRM_WRITE32(map, offset, val)   writel(val, ((void __iomem *)(map)->handle) + (offset))
33 #else
34 /** Read a byte from a MMIO region */
35 #define DRM_READ8(map, offset)          readb((map)->handle + (offset))
36 /** Read a word from a MMIO region */
37 #define DRM_READ16(map, offset)         readw((map)->handle + (offset))
38 /** Read a dword from a MMIO region */
39 #define DRM_READ32(map, offset)         readl((map)->handle + (offset))
40 /** Write a byte into a MMIO region */
41 #define DRM_WRITE8(map, offset, val)    writeb(val, (map)->handle + (offset))
42 /** Write a word into a MMIO region */
43 #define DRM_WRITE16(map, offset, val)   writew(val, (map)->handle + (offset))
44 /** Write a dword into a MMIO region */
45 #define DRM_WRITE32(map, offset, val)   writel(val, (map)->handle + (offset))
46 #endif
47 /** Read memory barrier */
48 #define DRM_READMEMORYBARRIER()         rmb()
49 /** Write memory barrier */
50 #define DRM_WRITEMEMORYBARRIER()        wmb()
51 /** Read/write memory barrier */
52 #define DRM_MEMORYBARRIER()             mb()
53 /** DRM device local declaration */
54 #define DRM_DEVICE      struct drm_file *priv   = filp->private_data; \
55                         struct drm_device *dev  = priv->head->dev
56
57 /** IRQ handler arguments and return type and values */
58 #define DRM_IRQ_ARGS            int irq, void *arg
59 /** backwards compatibility with old irq return values */
60 #ifndef IRQ_HANDLED
61 typedef void irqreturn_t;
62 #define IRQ_HANDLED             /* nothing */
63 #define IRQ_NONE                /* nothing */
64 #endif
65
66 /** AGP types */
67 #if __OS_HAS_AGP
68 #define DRM_AGP_MEM             struct agp_memory
69 #define DRM_AGP_KERN            struct agp_kern_info
70 #else
71 /* define some dummy types for non AGP supporting kernels */
72 struct no_agp_kern {
73         unsigned long aper_base;
74         unsigned long aper_size;
75 };
76 #define DRM_AGP_MEM             int
77 #define DRM_AGP_KERN            struct no_agp_kern
78 #endif
79
80 #if !(__OS_HAS_MTRR)
81 static __inline__ int mtrr_add(unsigned long base, unsigned long size,
82                                unsigned int type, char increment)
83 {
84         return -ENODEV;
85 }
86
87 static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
88 {
89         return -ENODEV;
90 }
91
92 #define MTRR_TYPE_WRCOMB     1
93 #endif
94
95 /** For data going into the kernel through the ioctl argument */
96 #define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3)      \
97         if ( copy_from_user(&arg1, arg2, arg3) )        \
98                 return -EFAULT
99 /** For data going from the kernel through the ioctl argument */
100 #define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3)        \
101         if ( copy_to_user(arg1, &arg2, arg3) )          \
102                 return -EFAULT
103 /** Other copying of data to kernel space */
104 #define DRM_COPY_FROM_USER(arg1, arg2, arg3)            \
105         copy_from_user(arg1, arg2, arg3)
106 /** Other copying of data from kernel space */
107 #define DRM_COPY_TO_USER(arg1, arg2, arg3)              \
108         copy_to_user(arg1, arg2, arg3)
109 /* Macros for copyfrom user, but checking readability only once */
110 #define DRM_VERIFYAREA_READ( uaddr, size )              \
111         (access_ok( VERIFY_READ, uaddr, size) ? 0 : -EFAULT)
112 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3)  \
113         __copy_from_user(arg1, arg2, arg3)
114 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3)    \
115         __copy_to_user(arg1, arg2, arg3)
116 #define DRM_GET_USER_UNCHECKED(val, uaddr)              \
117         __get_user(val, uaddr)
118
119 #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) _priv = _filp->private_data
120
121 #define DRM_HZ HZ
122
123 #define DRM_WAIT_ON( ret, queue, timeout, condition )           \
124 do {                                                            \
125         DECLARE_WAITQUEUE(entry, current);                      \
126         unsigned long end = jiffies + (timeout);                \
127         add_wait_queue(&(queue), &entry);                       \
128                                                                 \
129         for (;;) {                                              \
130                 __set_current_state(TASK_INTERRUPTIBLE);        \
131                 if (condition)                                  \
132                         break;                                  \
133                 if (time_after_eq(jiffies, end)) {              \
134                         ret = -EBUSY;                           \
135                         break;                                  \
136                 }                                               \
137                 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1);    \
138                 if (signal_pending(current)) {                  \
139                         ret = -EINTR;                           \
140                         break;                                  \
141                 }                                               \
142         }                                                       \
143         __set_current_state(TASK_RUNNING);                      \
144         remove_wait_queue(&(queue), &entry);                    \
145 } while (0)
146
147 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
148 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )