Use list_entry() to get container struct from struct list_head pointers.
[platform/upstream/libdrm.git] / linux-core / drm_os_linux.h
1 #define __NO_VERSION__
2
3 #include <linux/interrupt.h>    /* For task queue support */
4 #include <linux/delay.h>
5
6 #define DRMFILE                         struct file *
7 #define DRM_IOCTL_ARGS                  struct inode *inode, struct file *filp, unsigned int cmd, unsigned long data
8 #define DRM_ERR(d)                      -(d)
9 #define DRM_CURRENTPID                  current->pid
10 #define DRM_UDELAY(d)                   udelay(d)
11 #define DRM_READ8(map, offset)          readb(((unsigned long)(map)->handle) + (offset))
12 #define DRM_READ32(map, offset)         readl(((unsigned long)(map)->handle) + (offset))
13 #define DRM_WRITE8(map, offset, val)    writeb(val, ((unsigned long)(map)->handle) + (offset))
14 #define DRM_WRITE32(map, offset, val)   writel(val, ((unsigned long)(map)->handle) + (offset))
15 #define DRM_READMEMORYBARRIER(map)      mb()
16 #define DRM_WRITEMEMORYBARRIER(map)     wmb()
17 #define DRM_DEVICE      drm_file_t      *priv   = filp->private_data; \
18                         drm_device_t    *dev    = priv->dev
19
20 #define DRM_IRQ_ARGS            int irq, void *arg, struct pt_regs *regs
21 #define DRM_TASKQUEUE_ARGS      void *arg
22
23 /* For data going from/to the kernel through the ioctl argument */
24 #define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3)      \
25         if ( copy_from_user(&arg1, arg2, arg3) )        \
26                 return -EFAULT
27 #define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3)        \
28         if ( copy_to_user(arg1, &arg2, arg3) )          \
29                 return -EFAULT
30 /* Other copying of data from/to kernel space */
31 #define DRM_COPY_FROM_USER(arg1, arg2, arg3)            \
32         copy_from_user(arg1, arg2, arg3)
33 #define DRM_COPY_TO_USER(arg1, arg2, arg3)              \
34         copy_to_user(arg1, arg2, arg3)
35 /* Macros for copyfrom user, but checking readability only once */
36 #define DRM_VERIFYAREA_READ( uaddr, size )              \
37         verify_area( VERIFY_READ, uaddr, size )
38 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3)  \
39         __copy_from_user(arg1, arg2, arg3)
40 #define DRM_GET_USER_UNCHECKED(val, uaddr)              \
41         __get_user(val, uaddr)
42
43
44 /* malloc/free without the overhead of DRM(alloc) */
45 #define DRM_MALLOC(x) kmalloc(x, GFP_KERNEL)
46 #define DRM_FREE(x,size) kfree(x)
47
48 #define DRM_GETSAREA()                                                   \
49 do {                                                                     \
50         drm_map_list_t *entry;                                           \
51         list_for_each_entry( entry, &dev->maplist->head, head ) {        \
52                 if ( entry->map &&                                       \
53                      entry->map->type == _DRM_SHM &&                     \
54                      (entry->map->flags & _DRM_CONTAINS_LOCK) ) {        \
55                         dev_priv->sarea = entry->map;                    \
56                         break;                                           \
57                 }                                                        \
58         }                                                                \
59 } while (0)
60
61 #define DRM_HZ HZ
62
63 #define DRM_WAIT_ON( ret, queue, timeout, condition )           \
64 do {                                                            \
65         DECLARE_WAITQUEUE(entry, current);                      \
66         unsigned long end = jiffies + (timeout);                \
67         add_wait_queue(&(queue), &entry);                       \
68                                                                 \
69         for (;;) {                                              \
70                 current->state = TASK_INTERRUPTIBLE;            \
71                 if (condition)                                  \
72                         break;                                  \
73                 if((signed)(end - jiffies) <= 0) {              \
74                         ret = -EBUSY;                           \
75                         break;                                  \
76                 }                                               \
77                 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1);    \
78                 if (signal_pending(current)) {                  \
79                         ret = -EINTR;                           \
80                         break;                                  \
81                 }                                               \
82         }                                                       \
83         current->state = TASK_RUNNING;                          \
84         remove_wait_queue(&(queue), &entry);                    \
85 } while (0)
86
87
88 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
89 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )
90