3 * Memory mapping for DRM
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
10 * Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
12 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
13 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
14 * All Rights Reserved.
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of this software and associated documentation files (the "Software"),
18 * to deal in the Software without restriction, including without limitation
19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 * and/or sell copies of the Software, and to permit persons to whom the
21 * Software is furnished to do so, subject to the following conditions:
23 * The above copyright notice and this permission notice (including the next
24 * paragraph) shall be included in all copies or substantial portions of the
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
31 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
32 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33 * OTHER DEALINGS IN THE SOFTWARE.
39 #include <linux/efi.h>
42 static void drm_vm_open(struct vm_area_struct *vma);
43 static void drm_vm_close(struct vm_area_struct *vma);
44 static void drm_vm_ttm_close(struct vm_area_struct *vma);
45 static int drm_vm_ttm_open(struct vm_area_struct *vma);
46 static void drm_vm_ttm_open_wrapper(struct vm_area_struct *vma);
49 pgprot_t drm_io_prot(uint32_t map_type, struct vm_area_struct *vma)
51 pgprot_t tmp = vm_get_page_prot(vma->vm_flags);
53 #if defined(__i386__) || defined(__x86_64__)
54 if (boot_cpu_data.x86 > 3 && map_type != _DRM_AGP) {
55 pgprot_val(tmp) |= _PAGE_PCD;
56 pgprot_val(tmp) &= ~_PAGE_PWT;
58 #elif defined(__powerpc__)
59 pgprot_val(tmp) |= _PAGE_NO_CACHE;
60 if (map->type == _DRM_REGISTERS)
61 pgprot_val(tmp) |= _PAGE_GUARDED;
64 if (efi_range_is_wc(vma->vm_start, vma->vm_end -
66 tmp = pgprot_writecombine(tmp);
68 tmp = pgprot_noncached(tmp);
75 * \c nopage method for AGP virtual memory.
77 * \param vma virtual memory area.
78 * \param address access address.
79 * \return pointer to the page structure.
81 * Find the right map and if it's AGP memory find the real physical page to
82 * map, get the page, increment the use count and return it.
85 static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
86 unsigned long address)
88 drm_file_t *priv = vma->vm_file->private_data;
89 drm_device_t *dev = priv->head->dev;
90 drm_map_t *map = NULL;
91 drm_map_list_t *r_list;
92 drm_hash_item_t *hash;
97 if (!drm_core_has_AGP(dev))
100 if (!dev->agp || !dev->agp->cant_use_aperture)
101 goto vm_nopage_error;
103 if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff, &hash))
104 goto vm_nopage_error;
106 r_list = drm_hash_entry(hash, drm_map_list_t, hash);
109 if (map && map->type == _DRM_AGP) {
110 unsigned long offset = address - vma->vm_start;
111 unsigned long baddr = map->offset + offset;
112 struct drm_agp_mem *agpmem;
117 * Adjust to a bus-relative address
119 baddr -= dev->hose->mem_space->start;
123 * It's AGP memory - find the real physical page to map
125 for (agpmem = dev->agp->memory; agpmem; agpmem = agpmem->next) {
126 if (agpmem->bound <= baddr &&
127 agpmem->bound + agpmem->pages * PAGE_SIZE > baddr)
132 goto vm_nopage_error;
135 * Get the page, inc the use count, and return it
137 offset = (baddr - agpmem->bound) >> PAGE_SHIFT;
138 page = virt_to_page(__va(agpmem->memory->memory[offset]));
142 /* page_count() not defined everywhere */
144 ("baddr = 0x%lx page = 0x%p, offset = 0x%lx, count=%d\n",
145 baddr, __va(agpmem->memory->memory[offset]), offset,
152 return NOPAGE_SIGBUS; /* Disallow mremap */
154 #else /* __OS_HAS_AGP */
155 static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
156 unsigned long address)
158 return NOPAGE_SIGBUS;
160 #endif /* __OS_HAS_AGP */
162 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19))
165 struct page *drm_vm_ttm_fault(struct vm_area_struct *vma,
166 struct fault_data *data)
168 unsigned long address = data->address;
169 drm_local_map_t *map = (drm_local_map_t *) vma->vm_private_data;
170 unsigned long page_offset;
173 drm_buffer_manager_t *bm;
180 data->type = VM_FAULT_OOM;
184 if (address > vma->vm_end) {
185 data->type = VM_FAULT_SIGBUS;
189 ttm = (drm_ttm_t *) map->offset;
194 * Perhaps retry here?
197 mutex_lock(&dev->struct_mutex);
198 drm_fixup_ttm_caching(ttm);
201 page_offset = (address - vma->vm_start) >> PAGE_SHIFT;
202 page = ttm->pages[page_offset];
205 if (drm_alloc_memctl(PAGE_SIZE)) {
206 data->type = VM_FAULT_OOM;
209 page = ttm->pages[page_offset] = drm_alloc_gatt_pages(0);
211 drm_free_memctl(PAGE_SIZE);
212 data->type = VM_FAULT_OOM;
216 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
219 SetPageReserved(page);
223 if (ttm->page_flags & DRM_TTM_PAGE_UNCACHED) {
226 * FIXME: Check can't map aperture flag.
229 pfn = ttm->aper_offset + page_offset +
230 (ttm->be->aperture_base >> PAGE_SHIFT);
231 pgprot = drm_io_prot(ttm->be->drm_map_type, vma);
233 pfn = page_to_pfn(page);
234 pgprot = vma->vm_page_prot;
237 err = vm_insert_pfn(vma, address, pfn, pgprot);
239 if (!err || err == -EBUSY)
240 data->type = VM_FAULT_MINOR;
242 data->type = VM_FAULT_OOM;
244 mutex_unlock(&dev->struct_mutex);
250 * \c nopage method for shared virtual memory.
252 * \param vma virtual memory area.
253 * \param address access address.
254 * \return pointer to the page structure.
256 * Get the the mapping, find the real physical page to map, get the page, and
259 static __inline__ struct page *drm_do_vm_shm_nopage(struct vm_area_struct *vma,
260 unsigned long address)
262 drm_map_t *map = (drm_map_t *) vma->vm_private_data;
263 unsigned long offset;
267 if (address > vma->vm_end)
268 return NOPAGE_SIGBUS; /* Disallow mremap */
270 return NOPAGE_OOM; /* Nothing allocated */
272 offset = address - vma->vm_start;
273 i = (unsigned long)map->handle + offset;
274 page = vmalloc_to_page((void *)i);
279 DRM_DEBUG("shm_nopage 0x%lx\n", address);
284 * \c close method for shared virtual memory.
286 * \param vma virtual memory area.
288 * Deletes map information if we are the last
289 * person to close a mapping and it's not in the global maplist.
291 static void drm_vm_shm_close(struct vm_area_struct *vma)
293 drm_file_t *priv = vma->vm_file->private_data;
294 drm_device_t *dev = priv->head->dev;
295 drm_vma_entry_t *pt, *prev, *next;
297 drm_map_list_t *r_list;
298 struct list_head *list;
301 DRM_DEBUG("0x%08lx,0x%08lx\n",
302 vma->vm_start, vma->vm_end - vma->vm_start);
303 atomic_dec(&dev->vma_count);
305 map = vma->vm_private_data;
307 mutex_lock(&dev->struct_mutex);
308 for (pt = dev->vmalist, prev = NULL; pt; pt = next) {
310 if (pt->vma->vm_private_data == map)
312 if (pt->vma == vma) {
314 prev->next = pt->next;
316 dev->vmalist = pt->next;
318 drm_ctl_free(pt, sizeof(*pt), DRM_MEM_VMAS);
323 /* We were the only map that was found */
324 if (found_maps == 1 && map->flags & _DRM_REMOVABLE) {
325 /* Check to see if we are in the maplist, if we are not, then
326 * we delete this mappings information.
329 list = &dev->maplist->head;
330 list_for_each(list, &dev->maplist->head) {
331 r_list = list_entry(list, drm_map_list_t, head);
332 if (r_list->map == map)
337 drm_dma_handle_t dmah;
341 case _DRM_FRAME_BUFFER:
342 if (drm_core_has_MTRR(dev) && map->mtrr >= 0) {
344 retcode = mtrr_del(map->mtrr,
347 DRM_DEBUG("mtrr_del = %d\n", retcode);
349 drm_ioremapfree(map->handle, map->size, dev);
355 case _DRM_SCATTER_GATHER:
357 case _DRM_CONSISTENT:
358 dmah.vaddr = map->handle;
359 dmah.busaddr = map->offset;
360 dmah.size = map->size;
361 __drm_pci_free(dev, &dmah);
367 drm_free(map, sizeof(*map), DRM_MEM_MAPS);
370 mutex_unlock(&dev->struct_mutex);
374 * \c nopage method for DMA virtual memory.
376 * \param vma virtual memory area.
377 * \param address access address.
378 * \return pointer to the page structure.
380 * Determine the page number from the page offset and get it from drm_device_dma::pagelist.
382 static __inline__ struct page *drm_do_vm_dma_nopage(struct vm_area_struct *vma,
383 unsigned long address)
385 drm_file_t *priv = vma->vm_file->private_data;
386 drm_device_t *dev = priv->head->dev;
387 drm_device_dma_t *dma = dev->dma;
388 unsigned long offset;
389 unsigned long page_nr;
393 return NOPAGE_SIGBUS; /* Error */
394 if (address > vma->vm_end)
395 return NOPAGE_SIGBUS; /* Disallow mremap */
397 return NOPAGE_OOM; /* Nothing allocated */
399 offset = address - vma->vm_start; /* vm_[pg]off[set] should be 0 */
400 page_nr = offset >> PAGE_SHIFT;
401 page = virt_to_page((dma->pagelist[page_nr] + (offset & (~PAGE_MASK))));
405 DRM_DEBUG("dma_nopage 0x%lx (page %lu)\n", address, page_nr);
410 * \c nopage method for scatter-gather virtual memory.
412 * \param vma virtual memory area.
413 * \param address access address.
414 * \return pointer to the page structure.
416 * Determine the map offset from the page offset and get it from drm_sg_mem::pagelist.
418 static __inline__ struct page *drm_do_vm_sg_nopage(struct vm_area_struct *vma,
419 unsigned long address)
421 drm_map_t *map = (drm_map_t *) vma->vm_private_data;
422 drm_file_t *priv = vma->vm_file->private_data;
423 drm_device_t *dev = priv->head->dev;
424 drm_sg_mem_t *entry = dev->sg;
425 unsigned long offset;
426 unsigned long map_offset;
427 unsigned long page_offset;
432 return NOPAGE_SIGBUS; /* Error */
433 if (address > vma->vm_end)
434 return NOPAGE_SIGBUS; /* Disallow mremap */
435 if (!entry->pagelist)
436 return NOPAGE_OOM; /* Nothing allocated */
438 offset = address - vma->vm_start;
439 map_offset = map->offset - (unsigned long)dev->sg->virtual;
440 page_offset = (offset >> PAGE_SHIFT) + (map_offset >> PAGE_SHIFT);
441 page = entry->pagelist[page_offset];
447 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
449 static struct page *drm_vm_nopage(struct vm_area_struct *vma,
450 unsigned long address, int *type)
453 *type = VM_FAULT_MINOR;
454 return drm_do_vm_nopage(vma, address);
457 static struct page *drm_vm_shm_nopage(struct vm_area_struct *vma,
458 unsigned long address, int *type)
461 *type = VM_FAULT_MINOR;
462 return drm_do_vm_shm_nopage(vma, address);
465 static struct page *drm_vm_dma_nopage(struct vm_area_struct *vma,
466 unsigned long address, int *type)
469 *type = VM_FAULT_MINOR;
470 return drm_do_vm_dma_nopage(vma, address);
473 static struct page *drm_vm_sg_nopage(struct vm_area_struct *vma,
474 unsigned long address, int *type)
477 *type = VM_FAULT_MINOR;
478 return drm_do_vm_sg_nopage(vma, address);
482 #else /* LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0) */
484 static struct page *drm_vm_nopage(struct vm_area_struct *vma,
485 unsigned long address, int unused)
487 return drm_do_vm_nopage(vma, address);
490 static struct page *drm_vm_shm_nopage(struct vm_area_struct *vma,
491 unsigned long address, int unused)
493 return drm_do_vm_shm_nopage(vma, address);
496 static struct page *drm_vm_dma_nopage(struct vm_area_struct *vma,
497 unsigned long address, int unused)
499 return drm_do_vm_dma_nopage(vma, address);
502 static struct page *drm_vm_sg_nopage(struct vm_area_struct *vma,
503 unsigned long address, int unused)
505 return drm_do_vm_sg_nopage(vma, address);
510 /** AGP virtual memory operations */
511 static struct vm_operations_struct drm_vm_ops = {
512 .nopage = drm_vm_nopage,
514 .close = drm_vm_close,
517 /** Shared virtual memory operations */
518 static struct vm_operations_struct drm_vm_shm_ops = {
519 .nopage = drm_vm_shm_nopage,
521 .close = drm_vm_shm_close,
524 /** DMA virtual memory operations */
525 static struct vm_operations_struct drm_vm_dma_ops = {
526 .nopage = drm_vm_dma_nopage,
528 .close = drm_vm_close,
531 /** Scatter-gather virtual memory operations */
532 static struct vm_operations_struct drm_vm_sg_ops = {
533 .nopage = drm_vm_sg_nopage,
535 .close = drm_vm_close,
538 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
539 static struct vm_operations_struct drm_vm_ttm_ops = {
540 .nopage = drm_vm_ttm_nopage,
541 .open = drm_vm_ttm_open_wrapper,
542 .close = drm_vm_ttm_close,
545 static struct vm_operations_struct drm_vm_ttm_ops = {
546 .fault = drm_vm_ttm_fault,
547 .open = drm_vm_ttm_open_wrapper,
548 .close = drm_vm_ttm_close,
553 * \c open method for shared virtual memory.
555 * \param vma virtual memory area.
557 * Create a new drm_vma_entry structure as the \p vma private data entry and
558 * add it to drm_device::vmalist.
560 static void drm_vm_open(struct vm_area_struct *vma)
562 drm_file_t *priv = vma->vm_file->private_data;
563 drm_device_t *dev = priv->head->dev;
564 drm_vma_entry_t *vma_entry;
566 DRM_DEBUG("0x%08lx,0x%08lx\n",
567 vma->vm_start, vma->vm_end - vma->vm_start);
568 atomic_inc(&dev->vma_count);
570 vma_entry = drm_ctl_alloc(sizeof(*vma_entry), DRM_MEM_VMAS);
572 mutex_lock(&dev->struct_mutex);
573 vma_entry->vma = vma;
574 vma_entry->next = dev->vmalist;
575 vma_entry->pid = current->pid;
576 dev->vmalist = vma_entry;
577 mutex_unlock(&dev->struct_mutex);
581 static int drm_vm_ttm_open(struct vm_area_struct *vma) {
583 drm_local_map_t *map = (drm_local_map_t *)vma->vm_private_data;
585 drm_file_t *priv = vma->vm_file->private_data;
586 drm_device_t *dev = priv->head->dev;
589 mutex_lock(&dev->struct_mutex);
590 ttm = (drm_ttm_t *) map->offset;
591 atomic_inc(&ttm->vma_count);
592 #ifdef DRM_ODD_MM_COMPAT
593 drm_ttm_add_vma(ttm, vma);
595 mutex_unlock(&dev->struct_mutex);
599 static void drm_vm_ttm_open_wrapper(struct vm_area_struct *vma)
601 drm_vm_ttm_open(vma);
605 * \c close method for all virtual memory types.
607 * \param vma virtual memory area.
609 * Search the \p vma private data entry in drm_device::vmalist, unlink it, and
612 static void drm_vm_close(struct vm_area_struct *vma)
614 drm_file_t *priv = vma->vm_file->private_data;
615 drm_device_t *dev = priv->head->dev;
616 drm_vma_entry_t *pt, *prev;
618 DRM_DEBUG("0x%08lx,0x%08lx\n",
619 vma->vm_start, vma->vm_end - vma->vm_start);
620 atomic_dec(&dev->vma_count);
622 mutex_lock(&dev->struct_mutex);
623 for (pt = dev->vmalist, prev = NULL; pt; prev = pt, pt = pt->next) {
624 if (pt->vma == vma) {
626 prev->next = pt->next;
628 dev->vmalist = pt->next;
630 drm_ctl_free(pt, sizeof(*pt), DRM_MEM_VMAS);
634 mutex_unlock(&dev->struct_mutex);
638 static void drm_vm_ttm_close(struct vm_area_struct *vma)
640 drm_local_map_t *map = (drm_local_map_t *) vma->vm_private_data;
647 ttm = (drm_ttm_t *) map->offset;
649 mutex_lock(&dev->struct_mutex);
650 #ifdef DRM_ODD_MM_COMPAT
651 drm_ttm_delete_vma(ttm, vma);
653 if (atomic_dec_and_test(&ttm->vma_count)) {
655 ret = drm_destroy_ttm(ttm);
657 drm_ctl_free(map, sizeof(*map), DRM_MEM_TTM);
660 mutex_unlock(&dev->struct_mutex);
669 * \param filp file pointer.
670 * \param vma virtual memory area.
671 * \return zero on success or a negative number on failure.
673 * Sets the virtual memory area operations structure to vm_dma_ops, the file
674 * pointer, and calls vm_open().
676 static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
678 drm_file_t *priv = filp->private_data;
680 drm_device_dma_t *dma;
681 unsigned long length = vma->vm_end - vma->vm_start;
684 dev = priv->head->dev;
686 DRM_DEBUG("start = 0x%lx, end = 0x%lx, page offset = 0x%lx\n",
687 vma->vm_start, vma->vm_end, vma->vm_pgoff);
689 /* Length must match exact page count */
690 if (!dma || (length >> PAGE_SHIFT) != dma->page_count) {
696 if (!capable(CAP_SYS_ADMIN) &&
697 (dma->flags & _DRM_DMA_USE_PCI_RO)) {
698 vma->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
699 #if defined(__i386__) || defined(__x86_64__)
700 pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
702 /* Ye gads this is ugly. With more thought
703 we could move this up higher and use
704 `protection_map' instead. */
708 (__pte(pgprot_val(vma->vm_page_prot)))));
712 vma->vm_ops = &drm_vm_dma_ops;
714 #if LINUX_VERSION_CODE <= 0x02040e /* KERNEL_VERSION(2,4,14) */
715 vma->vm_flags |= VM_LOCKED | VM_SHM; /* Don't swap */
717 vma->vm_flags |= VM_RESERVED; /* Don't swap */
720 vma->vm_file = filp; /* Needed for drm_vm_open() */
725 unsigned long drm_core_get_map_ofs(drm_map_t * map)
729 EXPORT_SYMBOL(drm_core_get_map_ofs);
731 unsigned long drm_core_get_reg_ofs(struct drm_device *dev)
734 return dev->hose->dense_mem_base - dev->hose->mem_space->start;
739 EXPORT_SYMBOL(drm_core_get_reg_ofs);
744 * \param filp file pointer.
745 * \param vma virtual memory area.
746 * \return zero on success or a negative number on failure.
748 * If the virtual memory area has no offset associated with it then it's a DMA
749 * area, so calls mmap_dma(). Otherwise searches the map in drm_device::maplist,
750 * checks that the restricted flag is not set, sets the virtual memory operations
751 * according to the mapping type and remaps the pages. Finally sets the file
752 * pointer and calls vm_open().
754 int drm_mmap(struct file *filp, struct vm_area_struct *vma)
756 drm_file_t *priv = filp->private_data;
757 drm_device_t *dev = priv->head->dev;
758 drm_map_t *map = NULL;
759 unsigned long offset = 0;
760 drm_hash_item_t *hash;
762 DRM_DEBUG("start = 0x%lx, end = 0x%lx, page offset = 0x%lx\n",
763 vma->vm_start, vma->vm_end, vma->vm_pgoff);
765 if (!priv->authenticated)
768 /* We check for "dma". On Apple's UniNorth, it's valid to have
769 * the AGP mapped at physical address 0
775 || dev->agp->agp_info.device->vendor != PCI_VENDOR_ID_APPLE)
778 return drm_mmap_dma(filp, vma);
780 if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff , &hash)) {
781 DRM_ERROR("Could not find map\n");
785 map = drm_hash_entry(hash,drm_map_list_t, hash)->map;
787 if (!map || ((map->flags & _DRM_RESTRICTED) && !capable(CAP_SYS_ADMIN)))
790 /* Check for valid size. */
791 if (map->size < vma->vm_end - vma->vm_start)
794 if (!capable(CAP_SYS_ADMIN) && (map->flags & _DRM_READ_ONLY)) {
795 vma->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
796 #if defined(__i386__) || defined(__x86_64__)
797 pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
799 /* Ye gads this is ugly. With more thought
800 we could move this up higher and use
801 `protection_map' instead. */
805 (__pte(pgprot_val(vma->vm_page_prot)))));
811 if (drm_core_has_AGP(dev) && dev->agp->cant_use_aperture) {
813 * On some platforms we can't talk to bus dma address from the CPU, so for
814 * memory of type DRM_AGP, we'll deal with sorting out the real physical
815 * pages and mappings in nopage()
817 #if defined(__powerpc__)
818 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
820 vma->vm_ops = &drm_vm_ops;
823 /* fall through to _DRM_FRAME_BUFFER... */
824 case _DRM_FRAME_BUFFER:
826 offset = dev->driver->get_reg_ofs(dev);
827 vma->vm_flags |= VM_IO; /* not in core dump */
828 vma->vm_page_prot = drm_io_prot(map->type, vma);
830 if (io_remap_pfn_range(vma, vma->vm_start,
831 (map->offset + offset) >>PAGE_SHIFT,
832 vma->vm_end - vma->vm_start,
835 if (remap_pfn_range(vma, vma->vm_start,
836 (map->offset + offset) >> PAGE_SHIFT,
837 vma->vm_end - vma->vm_start,
841 DRM_DEBUG(" Type = %d; start = 0x%lx, end = 0x%lx,"
844 vma->vm_start, vma->vm_end, map->offset + offset);
845 vma->vm_ops = &drm_vm_ops;
847 case _DRM_CONSISTENT:
848 /* Consistent memory is really like shared memory. But
849 * it's allocated in a different way, so avoid nopage */
850 if (remap_pfn_range(vma, vma->vm_start,
851 page_to_pfn(virt_to_page(map->handle)),
852 vma->vm_end - vma->vm_start, vma->vm_page_prot))
854 /* fall through to _DRM_SHM */
856 vma->vm_ops = &drm_vm_shm_ops;
857 vma->vm_private_data = (void *)map;
858 /* Don't let this area swap. Change when
859 DRM_KERNEL advisory is supported. */
860 #if LINUX_VERSION_CODE <= 0x02040e /* KERNEL_VERSION(2,4,14) */
861 vma->vm_flags |= VM_LOCKED;
863 vma->vm_flags |= VM_RESERVED;
866 case _DRM_SCATTER_GATHER:
867 vma->vm_ops = &drm_vm_sg_ops;
868 vma->vm_private_data = (void *)map;
869 #if LINUX_VERSION_CODE <= 0x02040e /* KERNEL_VERSION(2,4,14) */
870 vma->vm_flags |= VM_LOCKED;
872 vma->vm_flags |= VM_RESERVED;
876 vma->vm_ops = &drm_vm_ttm_ops;
877 vma->vm_private_data = (void *) map;
879 vma->vm_flags |= VM_RESERVED | VM_IO;
880 #ifdef DRM_ODD_MM_COMPAT
881 mutex_lock(&dev->struct_mutex);
882 drm_ttm_map_bound(vma);
883 mutex_unlock(&dev->struct_mutex);
885 if (drm_vm_ttm_open(vma))
890 return -EINVAL; /* This should never happen. */
892 #if LINUX_VERSION_CODE <= 0x02040e /* KERNEL_VERSION(2,4,14) */
893 vma->vm_flags |= VM_LOCKED | VM_SHM; /* Don't swap */
895 vma->vm_flags |= VM_RESERVED; /* Don't swap */
898 vma->vm_file = filp; /* Needed for drm_vm_open() */
902 EXPORT_SYMBOL(drm_mmap);