Make the comment match the code
[platform/upstream/libdrm.git] / linux-core / 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 #if LINUX_VERSION_CODE <= 0x020608 /* KERNEL_VERSION(2,6,8) */
19 /** Read a byte from a MMIO region */
20 #define DRM_READ8(map, offset)          readb(((unsigned long)(map)->handle) + (offset))
21 /** Read a word from a MMIO region */
22 #define DRM_READ16(map, offset)         readw(((unsigned long)(map)->handle) + (offset))
23 /** Read a dword from a MMIO region */
24 #define DRM_READ32(map, offset)         readl(((unsigned long)(map)->handle) + (offset))
25 /** Write a byte into a MMIO region */
26 #define DRM_WRITE8(map, offset, val)    writeb(val, ((unsigned long)(map)->handle) + (offset))
27 /** Write a word into a MMIO region */
28 #define DRM_WRITE16(map, offset, val)   writew(val, ((unsigned long)(map)->handle) + (offset))
29 /** Write a dword into a MMIO region */
30 #define DRM_WRITE32(map, offset, val)   writel(val, ((unsigned long)(map)->handle) + (offset))
31 #else
32 /** Read a byte from a MMIO region */
33 #define DRM_READ8(map, offset)          readb((map)->handle + (offset))
34 /** Read a word from a MMIO region */
35 #define DRM_READ16(map, offset)         readw((map)->handle + (offset))
36 /** Read a dword from a MMIO region */
37 #define DRM_READ32(map, offset)         readl((map)->handle + (offset))
38 /** Write a byte into a MMIO region */
39 #define DRM_WRITE8(map, offset, val)    writeb(val, (map)->handle + (offset))
40 /** Write a word into a MMIO region */
41 #define DRM_WRITE16(map, offset, val)   writew(val, (map)->handle + (offset))
42 /** Write a dword into a MMIO region */
43 #define DRM_WRITE32(map, offset, val)   writel(val, (map)->handle + (offset))
44 #endif
45 /** Read memory barrier */
46 #define DRM_READMEMORYBARRIER()         rmb()
47 /** Write memory barrier */
48 #define DRM_WRITEMEMORYBARRIER()        wmb()
49 /** Read/write memory barrier */
50 #define DRM_MEMORYBARRIER()             mb()
51 /** DRM device local declaration */
52 #define DRM_DEVICE      drm_file_t      *priv   = filp->private_data; \
53                         drm_device_t    *dev    = priv->dev
54
55 /** IRQ handler arguments and return type and values */
56 #define DRM_IRQ_ARGS            int irq, void *arg, struct pt_regs *regs
57 /** backwards compatibility with old irq return values */
58 #ifndef IRQ_HANDLED
59 typedef void irqreturn_t;
60 #define IRQ_HANDLED   /* nothing */
61 #define IRQ_NONE      /* nothing */
62 #endif
63
64 /** AGP types */
65 #if __OS_HAS_AGP
66 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,70)
67 #define DRM_AGP_MEM             agp_memory
68 #define DRM_AGP_KERN            agp_kern_info
69 #else
70 #define DRM_AGP_MEM             struct agp_memory
71 #define DRM_AGP_KERN            struct agp_kern_info
72 #endif
73 #else
74 /* define some dummy types for non AGP supporting kernels */
75 struct no_agp_kern {
76         unsigned long aper_base;
77         unsigned long aper_size;
78 };
79 #define DRM_AGP_MEM             int
80 #define DRM_AGP_KERN            struct no_agp_kern
81 #endif
82
83 #if !(__OS_HAS_MTRR)
84 static __inline__ int mtrr_add (unsigned long base, unsigned long size,
85                                 unsigned int type, char increment)
86 {
87         return -ENODEV;
88 }
89
90 static __inline__ int mtrr_del (int reg, unsigned long base,
91                                 unsigned long size)
92 {
93         return -ENODEV;
94 }
95 #define MTRR_TYPE_WRCOMB     1
96 #endif
97
98 /** Task queue handler arguments */
99 #define DRM_TASKQUEUE_ARGS      void *arg
100
101 /** For data going into the kernel through the ioctl argument */
102 #define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3)      \
103         if ( copy_from_user(&arg1, arg2, arg3) )        \
104                 return -EFAULT
105 /** For data going from the kernel through the ioctl argument */
106 #define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3)        \
107         if ( copy_to_user(arg1, &arg2, arg3) )          \
108                 return -EFAULT
109 /** Other copying of data to kernel space */
110 #define DRM_COPY_FROM_USER(arg1, arg2, arg3)            \
111         copy_from_user(arg1, arg2, arg3)
112 /** Other copying of data from kernel space */
113 #define DRM_COPY_TO_USER(arg1, arg2, arg3)              \
114         copy_to_user(arg1, arg2, arg3)
115 /* Macros for copyfrom user, but checking readability only once */
116 #define DRM_VERIFYAREA_READ( uaddr, size )              \
117         verify_area( VERIFY_READ, uaddr, size )
118 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3)  \
119         __copy_from_user(arg1, arg2, arg3)
120 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3)    \
121         __copy_to_user(arg1, arg2, arg3)
122 #define DRM_GET_USER_UNCHECKED(val, uaddr)              \
123         __get_user(val, uaddr)
124 #define DRM_PUT_USER_UNCHECKED(uaddr, val)              \
125         __put_user(val, uaddr)
126
127
128 #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) _priv = _filp->private_data
129
130 /** 
131  * Get the pointer to the SAREA.
132  *
133  * Searches the SAREA on the mapping lists and points drm_device::sarea to it.
134  */
135 #define DRM_GETSAREA()                                                   \
136 do {                                                                     \
137         drm_map_list_t *entry;                                           \
138         list_for_each_entry( entry, &dev->maplist->head, head ) {        \
139                 if ( entry->map &&                                       \
140                      entry->map->type == _DRM_SHM &&                     \
141                      (entry->map->flags & _DRM_CONTAINS_LOCK) ) {        \
142                         dev_priv->sarea = entry->map;                    \
143                         break;                                           \
144                 }                                                        \
145         }                                                                \
146 } while (0)
147
148 #define DRM_HZ HZ
149
150 #define DRM_WAIT_ON( ret, queue, timeout, condition )           \
151 do {                                                            \
152         DECLARE_WAITQUEUE(entry, current);                      \
153         unsigned long end = jiffies + (timeout);                \
154         add_wait_queue(&(queue), &entry);                       \
155                                                                 \
156         for (;;) {                                              \
157                 current->state = TASK_INTERRUPTIBLE;            \
158                 if (condition)                                  \
159                         break;                                  \
160                 if (time_after_eq(jiffies, end)) {              \
161                         ret = -EBUSY;                           \
162                         break;                                  \
163                 }                                               \
164                 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1);    \
165                 if (signal_pending(current)) {                  \
166                         ret = -EINTR;                           \
167                         break;                                  \
168                 }                                               \
169         }                                                       \
170         current->state = TASK_RUNNING;                          \
171         remove_wait_queue(&(queue), &entry);                    \
172 } while (0)
173
174
175 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
176 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )
177