OSDN Git Service

Merge commit 'origin/master' into modesetting-gem
[android-x86/external-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
64 typedef _Bool bool;
65 enum {
66         false   = 0,
67         true    = 1
68 };
69
70 #endif
71
72 #ifndef list_for_each_safe
73 #define list_for_each_safe(pos, n, head)                                \
74         for (pos = (head)->next, n = pos->next; pos != (head);          \
75                 pos = n, n = pos->next)
76 #endif
77
78 #ifndef list_for_each_entry
79 #define list_for_each_entry(pos, head, member)                          \
80        for (pos = list_entry((head)->next, typeof(*pos), member),       \
81                     prefetch(pos->member.next);                         \
82             &pos->member != (head);                                     \
83             pos = list_entry(pos->member.next, typeof(*pos), member),   \
84                     prefetch(pos->member.next))
85 #endif
86
87 #ifndef list_for_each_entry_safe
88 #define list_for_each_entry_safe(pos, n, head, member)                  \
89         for (pos = list_entry((head)->next, typeof(*pos), member),      \
90                 n = list_entry(pos->member.next, typeof(*pos), member); \
91              &pos->member != (head);                                    \
92              pos = n, n = list_entry(n->member.next, typeof(*n), member))
93 #endif
94
95 #ifndef __user
96 #define __user
97 #endif
98
99 #if !defined(__put_page)
100 #define __put_page(p)           atomic_dec(&(p)->count)
101 #endif
102
103 #if !defined(__GFP_COMP)
104 #define __GFP_COMP 0
105 #endif
106
107 #if !defined(IRQF_SHARED)
108 #define IRQF_SHARED SA_SHIRQ
109 #endif
110
111 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
112 static inline int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t pgprot)
113 {
114   return remap_page_range(vma, from,
115                           pfn << PAGE_SHIFT,
116                           size,
117                           pgprot);
118 }
119
120 static __inline__ void *kcalloc(size_t nmemb, size_t size, int flags)
121 {
122         void *addr;
123
124         addr = kmalloc(size * nmemb, flags);
125         if (addr != NULL)
126                 memset((void *)addr, 0, size * nmemb);
127
128         return addr;
129 }
130 #endif
131
132 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
133 #define mutex_lock down
134 #define mutex_unlock up
135
136 #define mutex semaphore
137
138 #define mutex_init(a) sema_init((a), 1)
139
140 #endif
141
142 #ifndef DEFINE_SPINLOCK
143 #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
144 #endif
145
146 /* old architectures */
147 #ifdef __AMD64__
148 #define __x86_64__
149 #endif
150
151 /* sysfs __ATTR macro */
152 #ifndef __ATTR
153 #define __ATTR(_name,_mode,_show,_store) { \
154         .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE },     \
155         .show   = _show,                                        \
156         .store  = _store,                                       \
157 }
158 #endif
159
160 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
161 #define vmalloc_user(_size) ({void * tmp = vmalloc(_size);   \
162       if (tmp) memset(tmp, 0, _size);                        \
163       (tmp);})
164 #endif
165
166 #ifndef list_for_each_entry_safe_reverse
167 #define list_for_each_entry_safe_reverse(pos, n, head, member)          \
168         for (pos = list_entry((head)->prev, typeof(*pos), member),      \
169                 n = list_entry(pos->member.prev, typeof(*pos), member); \
170              &pos->member != (head);                                    \
171              pos = n, n = list_entry(n->member.prev, typeof(*n), member))
172 #endif
173
174 #include <linux/mm.h>
175 #include <asm/page.h>
176
177 #if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)) && \
178      (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)))
179 #define DRM_ODD_MM_COMPAT
180 #endif
181
182 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21))
183 #define DRM_FULL_MM_COMPAT
184 #endif
185
186
187 /*
188  * Flush relevant caches and clear a VMA structure so that page references
189  * will cause a page fault. Don't flush tlbs.
190  */
191
192 extern void drm_clear_vma(struct vm_area_struct *vma,
193                           unsigned long addr, unsigned long end);
194
195 /*
196  * Return the PTE protection map entries for the VMA flags given by
197  * flags. This is a functional interface to the kernel's protection map.
198  */
199
200 extern pgprot_t vm_get_page_prot(unsigned long vm_flags);
201
202 #ifndef GFP_DMA32
203 #define GFP_DMA32 GFP_KERNEL
204 #endif
205 #ifndef __GFP_DMA32
206 #define __GFP_DMA32 GFP_KERNEL
207 #endif
208
209 #if defined(CONFIG_X86) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
210
211 /*
212  * These are too slow in earlier kernels.
213  */
214
215 extern int drm_unmap_page_from_agp(struct page *page);
216 extern int drm_map_page_into_agp(struct page *page);
217
218 #define map_page_into_agp drm_map_page_into_agp
219 #define unmap_page_from_agp drm_unmap_page_from_agp
220 #endif
221
222 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
223 extern struct page *get_nopage_retry(void);
224 extern void free_nopage_retry(void);
225
226 #define NOPAGE_REFAULT get_nopage_retry()
227 #endif
228
229
230 #ifndef DRM_FULL_MM_COMPAT
231
232 /*
233  * For now, just return a dummy page that we've allocated out of
234  * static space. The page will be put by do_nopage() since we've already
235  * filled out the pte.
236  */
237
238 struct fault_data {
239         struct vm_area_struct *vma;
240         unsigned long address;
241         pgoff_t pgoff;
242         unsigned int flags;
243
244         int type;
245 };
246
247 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
248 extern struct page *drm_bo_vm_nopage(struct vm_area_struct *vma,
249                                      unsigned long address,
250                                      int *type);
251 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)) && \
252   !defined(DRM_FULL_MM_COMPAT)
253 extern unsigned long drm_bo_vm_nopfn(struct vm_area_struct *vma,
254                                      unsigned long address);
255 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)) */
256 #endif /* ndef DRM_FULL_MM_COMPAT */
257
258 #ifdef DRM_ODD_MM_COMPAT
259
260 struct drm_buffer_object;
261
262
263 /*
264  * Add a vma to the ttm vma list, and the
265  * process mm pointer to the ttm mm list. Needs the ttm mutex.
266  */
267
268 extern int drm_bo_add_vma(struct drm_buffer_object * bo,
269                            struct vm_area_struct *vma);
270 /*
271  * Delete a vma and the corresponding mm pointer from the
272  * ttm lists. Needs the ttm mutex.
273  */
274 extern void drm_bo_delete_vma(struct drm_buffer_object * bo,
275                               struct vm_area_struct *vma);
276
277 /*
278  * Attempts to lock all relevant mmap_sems for a ttm, while
279  * not releasing the ttm mutex. May return -EAGAIN to avoid
280  * deadlocks. In that case the caller shall release the ttm mutex,
281  * schedule() and try again.
282  */
283
284 extern int drm_bo_lock_kmm(struct drm_buffer_object * bo);
285
286 /*
287  * Unlock all relevant mmap_sems for a ttm.
288  */
289 extern void drm_bo_unlock_kmm(struct drm_buffer_object * bo);
290
291 /*
292  * If the ttm was bound to the aperture, this function shall be called
293  * with all relevant mmap sems held. It deletes the flag VM_PFNMAP from all
294  * vmas mapping this ttm. This is needed just after unmapping the ptes of
295  * the vma, otherwise the do_nopage() function will bug :(. The function
296  * releases the mmap_sems for this ttm.
297  */
298
299 extern void drm_bo_finish_unmap(struct drm_buffer_object *bo);
300
301 /*
302  * Remap all vmas of this ttm using io_remap_pfn_range. We cannot
303  * fault these pfns in, because the first one will set the vma VM_PFNMAP
304  * flag, which will make the next fault bug in do_nopage(). The function
305  * releases the mmap_sems for this ttm.
306  */
307
308 extern int drm_bo_remap_bound(struct drm_buffer_object *bo);
309
310
311 /*
312  * Remap a vma for a bound ttm. Call with the ttm mutex held and
313  * the relevant mmap_sem locked.
314  */
315 extern int drm_bo_map_bound(struct vm_area_struct *vma);
316
317 #endif
318
319 /* fixme when functions are upstreamed - upstreamed for 2.6.23 */
320 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23))
321 #define DRM_IDR_COMPAT_FN
322 #endif
323 #ifdef DRM_IDR_COMPAT_FN
324 int idr_for_each(struct idr *idp,
325                  int (*fn)(int id, void *p, void *data), void *data);
326 void idr_remove_all(struct idr *idp);
327 #endif
328
329
330 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
331 void *idr_replace(struct idr *idp, void *ptr, int id);
332 #endif
333
334 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
335 extern unsigned long round_jiffies_relative(unsigned long j);
336 #endif
337
338 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
339 extern struct pci_dev * pci_get_bus_and_slot(unsigned int bus, unsigned int devfn);
340 #endif
341
342 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
343 static inline int kobject_uevent_env(struct kobject *kobj,
344                                      enum kobject_action action,
345                                      char *envp[])
346 {
347     return 0;
348 }
349 #endif
350
351 #ifndef PM_EVENT_PRETHAW 
352 #define PM_EVENT_PRETHAW 3
353 #endif
354
355
356 #if (defined(CONFIG_X86) && defined(CONFIG_X86_32) && defined(CONFIG_HIGHMEM))
357 #define DRM_KMAP_ATOMIC_PROT_PFN
358 extern void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type,
359                                   pgprot_t protection);
360 #endif
361
362 #if !defined(flush_agp_mappings)
363 #define flush_agp_mappings() do {} while(0)
364 #endif
365
366 #ifndef DMA_BIT_MASK
367 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
368 #endif
369
370 #ifndef VM_CAN_NONLINEAR
371 #define DRM_VM_NOPAGE 1
372 #endif
373
374 #ifdef DRM_VM_NOPAGE
375
376 extern struct page *drm_vm_nopage(struct vm_area_struct *vma,
377                                   unsigned long address, int *type);
378
379 extern struct page *drm_vm_shm_nopage(struct vm_area_struct *vma,
380                                       unsigned long address, int *type);
381
382 extern struct page *drm_vm_dma_nopage(struct vm_area_struct *vma,
383                                       unsigned long address, int *type);
384
385 extern struct page *drm_vm_sg_nopage(struct vm_area_struct *vma,
386                                      unsigned long address, int *type);
387 #endif
388
389 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)
390 #define drm_on_each_cpu(handler, data, wait) \
391         on_each_cpu(handler, data, wait)
392 #else
393 #define drm_on_each_cpu(handler, data, wait) \
394         on_each_cpu(handler, data, wait, 1)
395 #endif
396
397 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
398 #define drm_core_ioremap_wc drm_core_ioremap
399 #endif
400
401 #endif