3 * Backward compatability definitions for Direct Rendering Manager
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
10 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
11 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
12 * All rights reserved.
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:
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
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.
34 #ifndef _DRM_COMPAT_H_
35 #define _DRM_COMPAT_H_
38 #define minor(x) MINOR((x))
41 #ifndef MODULE_LICENSE
42 #define MODULE_LICENSE(x)
45 #ifndef preempt_disable
46 #define preempt_disable()
47 #define preempt_enable()
50 #ifndef pte_offset_map
51 #define pte_offset_map pte_offset
52 #define pte_unmap(pte)
56 #define module_param(name, type, perm)
59 /* older kernels had different irq args */
60 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
62 #define DRM_IRQ_ARGS int irq, void *arg, struct pt_regs *regs
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)
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))
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))
99 #if !defined(__put_page)
100 #define __put_page(p) atomic_dec(&(p)->count)
103 #if !defined(__GFP_COMP)
107 #if !defined(IRQF_SHARED)
108 #define IRQF_SHARED SA_SHIRQ
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)
114 return remap_page_range(vma, from,
120 static __inline__ void *kcalloc(size_t nmemb, size_t size, int flags)
124 addr = kmalloc(size * nmemb, flags);
126 memset((void *)addr, 0, size * nmemb);
132 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
133 #define mutex_lock down
134 #define mutex_unlock up
136 #define mutex semaphore
138 #define mutex_init(a) sema_init((a), 1)
142 #ifndef DEFINE_SPINLOCK
143 #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
146 /* old architectures */
151 /* sysfs __ATTR macro */
153 #define __ATTR(_name,_mode,_show,_store) { \
154 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
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); \
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))
174 #include <linux/mm.h>
175 #include <asm/page.h>
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
182 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21))
183 #define DRM_FULL_MM_COMPAT
188 * Flush relevant caches and clear a VMA structure so that page references
189 * will cause a page fault. Don't flush tlbs.
192 extern void drm_clear_vma(struct vm_area_struct *vma,
193 unsigned long addr, unsigned long end);
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.
200 extern pgprot_t vm_get_page_prot(unsigned long vm_flags);
206 #if defined(CONFIG_X86) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
209 * These are too slow in earlier kernels.
212 extern int drm_unmap_page_from_agp(struct page *page);
213 extern int drm_map_page_into_agp(struct page *page);
215 #define map_page_into_agp drm_map_page_into_agp
216 #define unmap_page_from_agp drm_unmap_page_from_agp
219 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
220 extern struct page *get_nopage_retry(void);
221 extern void free_nopage_retry(void);
223 #define NOPAGE_REFAULT get_nopage_retry()
227 #ifndef DRM_FULL_MM_COMPAT
230 * For now, just return a dummy page that we've allocated out of
231 * static space. The page will be put by do_nopage() since we've already
232 * filled out the pte.
236 struct vm_area_struct *vma;
237 unsigned long address;
244 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
245 extern struct page *drm_bo_vm_nopage(struct vm_area_struct *vma,
246 unsigned long address,
248 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)) && \
249 !defined(DRM_FULL_MM_COMPAT)
250 extern unsigned long drm_bo_vm_nopfn(struct vm_area_struct *vma,
251 unsigned long address);
252 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)) */
253 #endif /* ndef DRM_FULL_MM_COMPAT */
255 #ifdef DRM_ODD_MM_COMPAT
257 struct drm_buffer_object;
261 * Add a vma to the ttm vma list, and the
262 * process mm pointer to the ttm mm list. Needs the ttm mutex.
265 extern int drm_bo_add_vma(struct drm_buffer_object * bo,
266 struct vm_area_struct *vma);
268 * Delete a vma and the corresponding mm pointer from the
269 * ttm lists. Needs the ttm mutex.
271 extern void drm_bo_delete_vma(struct drm_buffer_object * bo,
272 struct vm_area_struct *vma);
275 * Attempts to lock all relevant mmap_sems for a ttm, while
276 * not releasing the ttm mutex. May return -EAGAIN to avoid
277 * deadlocks. In that case the caller shall release the ttm mutex,
278 * schedule() and try again.
281 extern int drm_bo_lock_kmm(struct drm_buffer_object * bo);
284 * Unlock all relevant mmap_sems for a ttm.
286 extern void drm_bo_unlock_kmm(struct drm_buffer_object * bo);
289 * If the ttm was bound to the aperture, this function shall be called
290 * with all relevant mmap sems held. It deletes the flag VM_PFNMAP from all
291 * vmas mapping this ttm. This is needed just after unmapping the ptes of
292 * the vma, otherwise the do_nopage() function will bug :(. The function
293 * releases the mmap_sems for this ttm.
296 extern void drm_bo_finish_unmap(struct drm_buffer_object *bo);
299 * Remap all vmas of this ttm using io_remap_pfn_range. We cannot
300 * fault these pfns in, because the first one will set the vma VM_PFNMAP
301 * flag, which will make the next fault bug in do_nopage(). The function
302 * releases the mmap_sems for this ttm.
305 extern int drm_bo_remap_bound(struct drm_buffer_object *bo);
309 * Remap a vma for a bound ttm. Call with the ttm mutex held and
310 * the relevant mmap_sem locked.
312 extern int drm_bo_map_bound(struct vm_area_struct *vma);