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
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)
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))
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))
92 #if !defined(__put_page)
93 #define __put_page(p) atomic_dec(&(p)->count)
96 #if !defined(__GFP_COMP)
100 #define VM_OFFSET(vma) ((vma)->vm_pgoff << PAGE_SHIFT)
102 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
103 static inline int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t pgprot)
105 return remap_page_range(vma, from,
111 static __inline__ void *kcalloc(size_t nmemb, size_t size, int flags)
115 addr = kmalloc(size * nmemb, flags);
117 memset((void *)addr, 0, size * nmemb);
123 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
124 #define mutex_lock down
125 #define mutex_unlock up
127 #define mutex semaphore
129 #define mutex_init(a) sema_init((a), 1)
133 #ifndef DEFINE_SPINLOCK
134 #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
137 /* old architectures */
142 /* sysfs __ATTR macro */
144 #define __ATTR(_name,_mode,_show,_store) { \
145 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
151 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
152 #define vmalloc_user(_size) ({void * tmp = vmalloc(_size); \
153 if (tmp) memset(tmp, 0, size); \
158 #include <linux/mm.h>
159 #include <asm/page.h>
161 #if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)) && \
162 (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)))
163 #define DRM_ODD_MM_COMPAT
169 * Flush relevant caches and clear a VMA structure so that page references
170 * will cause a page fault. Don't flush tlbs.
173 extern void drm_clear_vma(struct vm_area_struct *vma,
174 unsigned long addr, unsigned long end);
177 * Return the PTE protection map entries for the VMA flags given by
178 * flags. This is a functional interface to the kernel's protection map.
181 extern pgprot_t vm_get_page_prot(unsigned long vm_flags);
187 #if defined(CONFIG_X86) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
190 * These are too slow in earlier kernels.
193 extern int drm_unmap_page_from_agp(struct page *page);
194 extern int drm_map_page_into_agp(struct page *page);
196 #define map_page_into_agp drm_map_page_into_agp
197 #define unmap_page_from_agp drm_unmap_page_from_agp
200 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
201 extern struct page *get_nopage_retry(void);
202 extern void free_nopage_retry(void);
204 extern struct page *drm_bo_vm_fault(struct vm_area_struct *vma,
205 struct fault_data *data);
207 #define NOPAGE_REFAULT get_nopage_retry()
211 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21))
214 * Hopefully, real NOPAGE_RETRY functionality will be in 2.6.19.
215 * For now, just return a dummy page that we've allocated out of
216 * static space. The page will be put by do_nopage() since we've already
217 * filled out the pte.
221 struct vm_area_struct *vma;
222 unsigned long address;
230 extern int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
231 unsigned long pfn, pgprot_t pgprot);
233 extern struct page *drm_bo_vm_nopage(struct vm_area_struct *vma,
234 unsigned long address,
239 #ifdef DRM_ODD_MM_COMPAT
241 struct drm_buffer_object;
245 * Add a vma to the ttm vma list, and the
246 * process mm pointer to the ttm mm list. Needs the ttm mutex.
249 extern int drm_bo_add_vma(struct drm_buffer_object * bo,
250 struct vm_area_struct *vma);
252 * Delete a vma and the corresponding mm pointer from the
253 * ttm lists. Needs the ttm mutex.
255 extern void drm_bo_delete_vma(struct drm_buffer_object * bo,
256 struct vm_area_struct *vma);
259 * Attempts to lock all relevant mmap_sems for a ttm, while
260 * not releasing the ttm mutex. May return -EAGAIN to avoid
261 * deadlocks. In that case the caller shall release the ttm mutex,
262 * schedule() and try again.
265 extern int drm_bo_lock_kmm(struct drm_buffer_object * bo);
268 * Unlock all relevant mmap_sems for a ttm.
270 extern void drm_bo_unlock_kmm(struct drm_buffer_object * bo);
273 * If the ttm was bound to the aperture, this function shall be called
274 * with all relevant mmap sems held. It deletes the flag VM_PFNMAP from all
275 * vmas mapping this ttm. This is needed just after unmapping the ptes of
276 * the vma, otherwise the do_nopage() function will bug :(. The function
277 * releases the mmap_sems for this ttm.
280 extern void drm_bo_finish_unmap(struct drm_buffer_object *bo);
283 * Remap all vmas of this ttm using io_remap_pfn_range. We cannot
284 * fault these pfns in, because the first one will set the vma VM_PFNMAP
285 * flag, which will make the next fault bug in do_nopage(). The function
286 * releases the mmap_sems for this ttm.
289 extern int drm_bo_remap_bound(struct drm_buffer_object *bo);
293 * Remap a vma for a bound ttm. Call with the ttm mutex held and
294 * the relevant mmap_sem locked.
296 extern int drm_bo_map_bound(struct vm_area_struct *vma);