Use fixed sized types in new ioctls
[profile/ivi/libdrm.git] / linux-core / drm_compat.h
1 /**
2  * \file drm_compat.h
3  * Backward compatability definitions for Direct Rendering Manager
4  *
5  * \author Rickard E. (Rik) Faith <faith@valinux.com>
6  * \author Gareth Hughes <gareth@valinux.com>
7  */
8
9 /*
10  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
11  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
12  * All rights reserved.
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the "Software"),
16  * to deal in the Software without restriction, including without limitation
17  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18  * and/or sell copies of the Software, and to permit persons to whom the
19  * Software is furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice and this permission notice (including the next
22  * paragraph) shall be included in all copies or substantial portions of the
23  * Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
28  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
29  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
31  * OTHER DEALINGS IN THE SOFTWARE.
32  */
33
34 #ifndef _DRM_COMPAT_H_
35 #define _DRM_COMPAT_H_
36
37 #ifndef minor
38 #define minor(x) MINOR((x))
39 #endif
40
41 #ifndef MODULE_LICENSE
42 #define MODULE_LICENSE(x)
43 #endif
44
45 #ifndef preempt_disable
46 #define preempt_disable()
47 #define preempt_enable()
48 #endif
49
50 #ifndef pte_offset_map
51 #define pte_offset_map pte_offset
52 #define pte_unmap(pte)
53 #endif
54
55 #ifndef module_param
56 #define module_param(name, type, perm)
57 #endif
58
59 /* older kernels had different irq args */
60 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
61 #undef DRM_IRQ_ARGS
62 #define DRM_IRQ_ARGS            int irq, void *arg, struct pt_regs *regs
63 #endif
64
65 #ifndef list_for_each_safe
66 #define list_for_each_safe(pos, n, head)                                \
67         for (pos = (head)->next, n = pos->next; pos != (head);          \
68                 pos = n, n = pos->next)
69 #endif
70
71 #ifndef list_for_each_entry
72 #define list_for_each_entry(pos, head, member)                          \
73        for (pos = list_entry((head)->next, typeof(*pos), member),       \
74                     prefetch(pos->member.next);                         \
75             &pos->member != (head);                                     \
76             pos = list_entry(pos->member.next, typeof(*pos), member),   \
77                     prefetch(pos->member.next))
78 #endif
79
80 #ifndef list_for_each_entry_safe
81 #define list_for_each_entry_safe(pos, n, head, member)                  \
82         for (pos = list_entry((head)->next, typeof(*pos), member),      \
83                 n = list_entry(pos->member.next, typeof(*pos), member); \
84              &pos->member != (head);                                    \
85              pos = n, n = list_entry(n->member.next, typeof(*n), member))
86 #endif
87
88 #ifndef __user
89 #define __user
90 #endif
91
92 #if !defined(__put_page)
93 #define __put_page(p)           atomic_dec(&(p)->count)
94 #endif
95
96 #if !defined(__GFP_COMP)
97 #define __GFP_COMP 0
98 #endif
99
100 #if !defined(IRQF_SHARED)
101 #define IRQF_SHARED SA_SHIRQ
102 #endif
103
104 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
105 static inline int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t pgprot)
106 {
107   return remap_page_range(vma, from,
108                           pfn << PAGE_SHIFT,
109                           size,
110                           pgprot);
111 }
112
113 static __inline__ void *kcalloc(size_t nmemb, size_t size, int flags)
114 {
115         void *addr;
116
117         addr = kmalloc(size * nmemb, flags);
118         if (addr != NULL)
119                 memset((void *)addr, 0, size * nmemb);
120
121         return addr;
122 }
123 #endif
124
125 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
126 #define mutex_lock down
127 #define mutex_unlock up
128
129 #define mutex semaphore
130
131 #define mutex_init(a) sema_init((a), 1)
132
133 #endif
134
135 #ifndef DEFINE_SPINLOCK
136 #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
137 #endif
138
139 /* old architectures */
140 #ifdef __AMD64__
141 #define __x86_64__
142 #endif
143
144 /* sysfs __ATTR macro */
145 #ifndef __ATTR
146 #define __ATTR(_name,_mode,_show,_store) { \
147         .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE },     \
148         .show   = _show,                                        \
149         .store  = _store,                                       \
150 }
151 #endif
152
153 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
154 #define vmalloc_user(_size) ({void * tmp = vmalloc(_size);   \
155       if (tmp) memset(tmp, 0, size);                         \
156       (tmp);})
157 #endif
158
159 #ifndef list_for_each_entry_safe_reverse
160 #define list_for_each_entry_safe_reverse(pos, n, head, member)          \
161         for (pos = list_entry((head)->prev, typeof(*pos), member),      \
162                 n = list_entry(pos->member.prev, typeof(*pos), member); \
163              &pos->member != (head);                                    \
164              pos = n, n = list_entry(n->member.prev, typeof(*n), member))
165 #endif
166
167 #include <linux/mm.h>
168 #include <asm/page.h>
169
170 #if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)) && \
171      (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)))
172 #define DRM_ODD_MM_COMPAT
173 #endif
174
175 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21))
176 #define DRM_FULL_MM_COMPAT
177 #endif
178
179
180 /*
181  * Flush relevant caches and clear a VMA structure so that page references
182  * will cause a page fault. Don't flush tlbs.
183  */
184
185 extern void drm_clear_vma(struct vm_area_struct *vma,
186                           unsigned long addr, unsigned long end);
187
188 /*
189  * Return the PTE protection map entries for the VMA flags given by
190  * flags. This is a functional interface to the kernel's protection map.
191  */
192
193 extern pgprot_t vm_get_page_prot(unsigned long vm_flags);
194
195 #ifndef GFP_DMA32
196 #define GFP_DMA32 GFP_KERNEL
197 #endif
198 #ifndef __GFP_DMA32
199 #define __GFP_DMA32 GFP_KERNEL
200 #endif
201
202 #if defined(CONFIG_X86) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
203
204 /*
205  * These are too slow in earlier kernels.
206  */
207
208 extern int drm_unmap_page_from_agp(struct page *page);
209 extern int drm_map_page_into_agp(struct page *page);
210
211 #define map_page_into_agp drm_map_page_into_agp
212 #define unmap_page_from_agp drm_unmap_page_from_agp
213 #endif
214
215 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
216 extern struct page *get_nopage_retry(void);
217 extern void free_nopage_retry(void);
218
219 #define NOPAGE_REFAULT get_nopage_retry()
220 #endif
221
222
223 #ifndef DRM_FULL_MM_COMPAT
224
225 /*
226  * For now, just return a dummy page that we've allocated out of
227  * static space. The page will be put by do_nopage() since we've already
228  * filled out the pte.
229  */
230
231 struct fault_data {
232         struct vm_area_struct *vma;
233         unsigned long address;
234         pgoff_t pgoff;
235         unsigned int flags;
236
237         int type;
238 };
239
240 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
241 extern struct page *drm_bo_vm_nopage(struct vm_area_struct *vma,
242                                      unsigned long address,
243                                      int *type);
244 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)) && \
245   !defined(DRM_FULL_MM_COMPAT)
246 extern unsigned long drm_bo_vm_nopfn(struct vm_area_struct *vma,
247                                      unsigned long address);
248 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)) */
249 #endif /* ndef DRM_FULL_MM_COMPAT */
250
251 #ifdef DRM_ODD_MM_COMPAT
252
253 struct drm_buffer_object;
254
255
256 /*
257  * Add a vma to the ttm vma list, and the
258  * process mm pointer to the ttm mm list. Needs the ttm mutex.
259  */
260
261 extern int drm_bo_add_vma(struct drm_buffer_object * bo,
262                            struct vm_area_struct *vma);
263 /*
264  * Delete a vma and the corresponding mm pointer from the
265  * ttm lists. Needs the ttm mutex.
266  */
267 extern void drm_bo_delete_vma(struct drm_buffer_object * bo,
268                               struct vm_area_struct *vma);
269
270 /*
271  * Attempts to lock all relevant mmap_sems for a ttm, while
272  * not releasing the ttm mutex. May return -EAGAIN to avoid
273  * deadlocks. In that case the caller shall release the ttm mutex,
274  * schedule() and try again.
275  */
276
277 extern int drm_bo_lock_kmm(struct drm_buffer_object * bo);
278
279 /*
280  * Unlock all relevant mmap_sems for a ttm.
281  */
282 extern void drm_bo_unlock_kmm(struct drm_buffer_object * bo);
283
284 /*
285  * If the ttm was bound to the aperture, this function shall be called
286  * with all relevant mmap sems held. It deletes the flag VM_PFNMAP from all
287  * vmas mapping this ttm. This is needed just after unmapping the ptes of
288  * the vma, otherwise the do_nopage() function will bug :(. The function
289  * releases the mmap_sems for this ttm.
290  */
291
292 extern void drm_bo_finish_unmap(struct drm_buffer_object *bo);
293
294 /*
295  * Remap all vmas of this ttm using io_remap_pfn_range. We cannot
296  * fault these pfns in, because the first one will set the vma VM_PFNMAP
297  * flag, which will make the next fault bug in do_nopage(). The function
298  * releases the mmap_sems for this ttm.
299  */
300
301 extern int drm_bo_remap_bound(struct drm_buffer_object *bo);
302
303
304 /*
305  * Remap a vma for a bound ttm. Call with the ttm mutex held and
306  * the relevant mmap_sem locked.
307  */
308 extern int drm_bo_map_bound(struct vm_area_struct *vma);
309
310 #endif
311
312 /* fixme when functions are upstreamed - upstreamed for 2.6.23 */
313 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23))
314 #define DRM_IDR_COMPAT_FN
315 #endif
316 #ifdef DRM_IDR_COMPAT_FN
317 int idr_for_each(struct idr *idp,
318                  int (*fn)(int id, void *p, void *data), void *data);
319 void idr_remove_all(struct idr *idp);
320 #endif
321
322
323 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
324 void *idr_replace(struct idr *idp, void *ptr, int id);
325 #endif
326
327 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
328 typedef _Bool                   bool;
329 #endif
330
331
332 #if (defined(CONFIG_X86) && defined(CONFIG_X86_32) && defined(CONFIG_HIMEM))
333 #define DRM_KMAP_ATOMIC_PROT_PFN
334 extern void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type,
335                                   pgprot_t protection);
336 #endif
337
338 #if !defined(flush_agp_mappings)
339 #define flush_agp_mappings() do {} while(0)
340 #endif
341
342 #ifndef DMA_BIT_MASK
343 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
344 #endif
345
346 #endif