patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / char / drm / drm_os_linux.h
1 /**
2  * \file drm_os_linux.h
3  * OS abstraction macros.
4  */
5
6
7 #include <linux/interrupt.h>    /* For task queue support */
8 #include <linux/delay.h>
9
10 /** File pointer type */
11 #define DRMFILE                         struct file *
12 /** Ioctl arguments */
13 #define DRM_IOCTL_ARGS                  struct inode *inode, struct file *filp, unsigned int cmd, unsigned long data
14 #define DRM_ERR(d)                      -(d)
15 /** Current process ID */
16 #define DRM_CURRENTPID                  current->pid
17 #define DRM_UDELAY(d)                   udelay(d)
18 /** Read a byte from a MMIO region */
19 #define DRM_READ8(map, offset)          readb(((unsigned long)(map)->handle) + (offset))
20 /** Read a dword from a MMIO region */
21 #define DRM_READ32(map, offset)         readl(((unsigned long)(map)->handle) + (offset))
22 /** Write a byte into a MMIO region */
23 #define DRM_WRITE8(map, offset, val)    writeb(val, ((unsigned long)(map)->handle) + (offset))
24 /** Write a dword into a MMIO region */
25 #define DRM_WRITE32(map, offset, val)   writel(val, ((unsigned long)(map)->handle) + (offset))
26 /** Read memory barrier */
27 #define DRM_READMEMORYBARRIER()         rmb()
28 /** Write memory barrier */
29 #define DRM_WRITEMEMORYBARRIER()        wmb()
30 /** Read/write memory barrier */
31 #define DRM_MEMORYBARRIER()             mb()
32 /** DRM device local declaration */
33 #define DRM_DEVICE      drm_file_t      *priv   = filp->private_data; \
34                         drm_device_t    *dev    = priv->dev
35
36 /** IRQ handler arguments and return type and values */
37 #define DRM_IRQ_ARGS            int irq, void *arg, struct pt_regs *regs
38
39 /** AGP types */
40 #define DRM_AGP_MEM             struct agp_memory
41 #define DRM_AGP_KERN            struct agp_kern_info
42
43 /** Task queue handler arguments */
44 #define DRM_TASKQUEUE_ARGS      void *arg
45
46 /** For data going into the kernel through the ioctl argument */
47 #define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3)      \
48         if ( copy_from_user(&arg1, arg2, arg3) )        \
49                 return -EFAULT
50 /** For data going from the kernel through the ioctl argument */
51 #define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3)        \
52         if ( copy_to_user(arg1, &arg2, arg3) )          \
53                 return -EFAULT
54 /** Other copying of data to kernel space */
55 #define DRM_COPY_FROM_USER(arg1, arg2, arg3)            \
56         copy_from_user(arg1, arg2, arg3)
57 /** Other copying of data from kernel space */
58 #define DRM_COPY_TO_USER(arg1, arg2, arg3)              \
59         copy_to_user(arg1, arg2, arg3)
60 /* Macros for copyfrom user, but checking readability only once */
61 #define DRM_VERIFYAREA_READ( uaddr, size )              \
62         verify_area( VERIFY_READ, uaddr, size )
63 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3)  \
64         __copy_from_user(arg1, arg2, arg3)
65 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3)    \
66         __copy_to_user(arg1, arg2, arg3)
67 #define DRM_GET_USER_UNCHECKED(val, uaddr)              \
68         __get_user(val, uaddr)
69 #define DRM_PUT_USER_UNCHECKED(uaddr, val)              \
70         __put_user(val, uaddr)
71
72
73 /** 'malloc' without the overhead of DRM(alloc)() */
74 #define DRM_MALLOC(x) kmalloc(x, GFP_KERNEL)
75 /** 'free' without the overhead of DRM(free)() */
76 #define DRM_FREE(x,size) kfree(x)
77
78 #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) _priv = _filp->private_data
79
80 /** 
81  * Get the pointer to the SAREA.
82  *
83  * Searches the SAREA on the mapping lists and points drm_device::sarea to it.
84  */
85 #define DRM_GETSAREA()                                                   \
86 do {                                                                     \
87         drm_map_list_t *entry;                                           \
88         list_for_each_entry( entry, &dev->maplist->head, head ) {        \
89                 if ( entry->map &&                                       \
90                      entry->map->type == _DRM_SHM &&                     \
91                      (entry->map->flags & _DRM_CONTAINS_LOCK) ) {        \
92                         dev_priv->sarea = entry->map;                    \
93                         break;                                           \
94                 }                                                        \
95         }                                                                \
96 } while (0)
97
98 #define DRM_HZ HZ
99
100 #define DRM_WAIT_ON( ret, queue, timeout, condition )           \
101 do {                                                            \
102         DECLARE_WAITQUEUE(entry, current);                      \
103         unsigned long end = jiffies + (timeout);                \
104         add_wait_queue(&(queue), &entry);                       \
105                                                                 \
106         for (;;) {                                              \
107                 current->state = TASK_INTERRUPTIBLE;            \
108                 if (condition)                                  \
109                         break;                                  \
110                 if (time_after_eq(jiffies, end)) {              \
111                         ret = -EBUSY;                           \
112                         break;                                  \
113                 }                                               \
114                 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1);    \
115                 if (signal_pending(current)) {                  \
116                         ret = -EINTR;                           \
117                         break;                                  \
118                 }                                               \
119         }                                                       \
120         current->state = TASK_RUNNING;                          \
121         remove_wait_queue(&(queue), &entry);                    \
122 } while (0)
123
124
125 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
126 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )
127