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 int drm_bo_mmap_locked(struct vm_area_struct *vma,
46 drm_local_map_t *map);
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;
62 #elif defined(__ia64__)
63 if (efi_range_is_wc(vma->vm_start, vma->vm_end -
65 tmp = pgprot_writecombine(tmp);
67 tmp = pgprot_noncached(tmp);
68 #elif defined(__sparc__)
69 tmp = pgprot_noncached(tmp);
74 static pgprot_t drm_dma_prot(uint32_t map_type, struct vm_area_struct *vma)
76 pgprot_t tmp = vm_get_page_prot(vma->vm_flags);
78 #if defined(__powerpc__) && defined(CONFIG_NOT_COHERENT_CACHE)
79 tmp |= _PAGE_NO_CACHE;
86 * \c fault method for AGP virtual memory.
88 * \param vma virtual memory area.
89 * \param address access address.
90 * \return pointer to the page structure.
92 * Find the right map and if it's AGP memory find the real physical page to
93 * map, get the page, increment the use count and return it.
96 static int drm_do_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
98 struct drm_file *priv = vma->vm_file->private_data;
99 struct drm_device *dev = priv->minor->dev;
100 struct drm_map *map = NULL;
101 struct drm_map_list *r_list;
102 struct drm_hash_item *hash;
107 if (!drm_core_has_AGP(dev))
110 if (!dev->agp || !dev->agp->cant_use_aperture)
113 if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff, &hash))
116 r_list = drm_hash_entry(hash, struct drm_map_list, hash);
119 if (map && map->type == _DRM_AGP) {
121 * Using vm_pgoff as a selector forces us to use this unusual
124 unsigned long offset = (unsigned long)vmf->virtual_address -
126 unsigned long baddr = map->offset + offset;
127 struct drm_agp_mem *agpmem;
132 * Adjust to a bus-relative address
134 baddr -= dev->hose->mem_space->start;
138 * It's AGP memory - find the real physical page to map
140 list_for_each_entry(agpmem, &dev->agp->memory, head) {
141 if (agpmem->bound <= baddr &&
142 agpmem->bound + agpmem->pages * PAGE_SIZE > baddr)
150 * Get the page, inc the use count, and return it
152 offset = (baddr - agpmem->bound) >> PAGE_SHIFT;
153 page = virt_to_page(__va(agpmem->memory->memory[offset]));
158 ("baddr = 0x%lx page = 0x%p, offset = 0x%lx, count=%d\n",
159 baddr, __va(agpmem->memory->memory[offset]), offset,
164 return VM_FAULT_SIGBUS; /* Disallow mremap */
166 #else /* __OS_HAS_AGP */
167 static int drm_do_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
169 return VM_FAULT_SIGBUS;
171 #endif /* __OS_HAS_AGP */
174 * \c nopage method for shared virtual memory.
176 * \param vma virtual memory area.
177 * \param address access address.
178 * \return pointer to the page structure.
180 * Get the mapping, find the real physical page to map, get the page, and
183 static int drm_do_vm_shm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
185 struct drm_map *map = (struct drm_map *) vma->vm_private_data;
186 unsigned long offset;
191 return VM_FAULT_SIGBUS; /* Nothing allocated */
193 offset = (unsigned long)vmf->virtual_address - vma->vm_start;
194 i = (unsigned long)map->handle + offset;
195 page = vmalloc_to_page((void *)i);
197 return VM_FAULT_SIGBUS;
201 DRM_DEBUG("shm_fault 0x%lx\n", offset);
207 * \c close method for shared virtual memory.
209 * \param vma virtual memory area.
211 * Deletes map information if we are the last
212 * person to close a mapping and it's not in the global maplist.
214 static void drm_vm_shm_close(struct vm_area_struct *vma)
216 struct drm_file *priv = vma->vm_file->private_data;
217 struct drm_device *dev = priv->minor->dev;
218 struct drm_vma_entry *pt, *temp;
220 struct drm_map_list *r_list;
223 DRM_DEBUG("0x%08lx,0x%08lx\n",
224 vma->vm_start, vma->vm_end - vma->vm_start);
225 atomic_dec(&dev->vma_count);
227 map = vma->vm_private_data;
229 mutex_lock(&dev->struct_mutex);
230 list_for_each_entry_safe(pt, temp, &dev->vmalist, head) {
231 if (pt->vma->vm_private_data == map)
233 if (pt->vma == vma) {
235 drm_ctl_free(pt, sizeof(*pt), DRM_MEM_VMAS);
238 /* We were the only map that was found */
239 if (found_maps == 1 && map->flags & _DRM_REMOVABLE) {
240 /* Check to see if we are in the maplist, if we are not, then
241 * we delete this mappings information.
244 list_for_each_entry(r_list, &dev->maplist, head) {
245 if (r_list->map == map)
250 drm_dma_handle_t dmah;
254 case _DRM_FRAME_BUFFER:
255 if (drm_core_has_MTRR(dev) && map->mtrr >= 0) {
257 retcode = mtrr_del(map->mtrr,
260 DRM_DEBUG("mtrr_del = %d\n", retcode);
262 iounmap(map->handle);
268 case _DRM_SCATTER_GATHER:
270 case _DRM_CONSISTENT:
271 dmah.vaddr = map->handle;
272 dmah.busaddr = map->offset;
273 dmah.size = map->size;
274 __drm_pci_free(dev, &dmah);
280 drm_free(map, sizeof(*map), DRM_MEM_MAPS);
283 mutex_unlock(&dev->struct_mutex);
286 #ifndef DRM_VM_NOPAGE
288 * \c fault method for DMA virtual memory.
290 * \param vma virtual memory area.
291 * \param address access address.
292 * \return pointer to the page structure.
294 * Determine the page number from the page offset and get it from drm_device_dma::pagelist.
296 static int drm_do_vm_dma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
298 struct drm_file *priv = vma->vm_file->private_data;
299 struct drm_device *dev = priv->minor->dev;
300 struct drm_device_dma *dma = dev->dma;
301 unsigned long offset;
302 unsigned long page_nr;
306 return VM_FAULT_SIGBUS; /* Error */
308 return VM_FAULT_SIGBUS; /* Nothing allocated */
310 offset = (unsigned long)vmf->virtual_address - vma->vm_start; /* vm_[pg]off[set] should be 0 */
311 page_nr = offset >> PAGE_SHIFT; /* page_nr could just be vmf->pgoff */
312 page = virt_to_page((dma->pagelist[page_nr] + (offset & (~PAGE_MASK))));
317 DRM_DEBUG("dma_fault 0x%lx (page %lu)\n", offset, page_nr);
322 * \c fault method for scatter-gather virtual memory.
324 * \param vma virtual memory area.
325 * \param address access address.
326 * \return pointer to the page structure.
328 * Determine the map offset from the page offset and get it from drm_sg_mem::pagelist.
330 static int drm_do_vm_sg_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
332 struct drm_map *map = (struct drm_map *) vma->vm_private_data;
333 struct drm_file *priv = vma->vm_file->private_data;
334 struct drm_device *dev = priv->minor->dev;
335 struct drm_sg_mem *entry = dev->sg;
336 unsigned long offset;
337 unsigned long map_offset;
338 unsigned long page_offset;
342 return VM_FAULT_SIGBUS; /* Error */
343 if (!entry->pagelist)
344 return VM_FAULT_SIGBUS; /* Nothing allocated */
346 offset = (unsigned long)vmf->virtual_address - vma->vm_start;
347 map_offset = map->offset - (unsigned long)dev->sg->virtual;
348 page_offset = (offset >> PAGE_SHIFT) + (map_offset >> PAGE_SHIFT);
349 page = entry->pagelist[page_offset];
357 /** AGP virtual memory operations */
358 static struct vm_operations_struct drm_vm_ops = {
360 .nopage = drm_vm_nopage,
362 .fault = drm_do_vm_fault,
365 .close = drm_vm_close,
368 /** Shared virtual memory operations */
369 static struct vm_operations_struct drm_vm_shm_ops = {
371 .nopage = drm_vm_shm_nopage,
373 .fault = drm_do_vm_shm_fault,
376 .close = drm_vm_shm_close,
379 /** DMA virtual memory operations */
380 static struct vm_operations_struct drm_vm_dma_ops = {
382 .nopage = drm_vm_dma_nopage,
384 .fault = drm_do_vm_dma_fault,
387 .close = drm_vm_close,
390 /** Scatter-gather virtual memory operations */
391 static struct vm_operations_struct drm_vm_sg_ops = {
393 .nopage = drm_vm_sg_nopage,
395 .fault = drm_do_vm_sg_fault,
398 .close = drm_vm_close,
402 * \c open method for shared virtual memory.
404 * \param vma virtual memory area.
406 * Create a new drm_vma_entry structure as the \p vma private data entry and
407 * add it to drm_device::vmalist.
409 static void drm_vm_open_locked(struct vm_area_struct *vma)
411 struct drm_file *priv = vma->vm_file->private_data;
412 struct drm_device *dev = priv->minor->dev;
413 struct drm_vma_entry *vma_entry;
415 DRM_DEBUG("0x%08lx,0x%08lx\n",
416 vma->vm_start, vma->vm_end - vma->vm_start);
417 atomic_inc(&dev->vma_count);
419 vma_entry = drm_ctl_alloc(sizeof(*vma_entry), DRM_MEM_VMAS);
421 vma_entry->vma = vma;
422 vma_entry->pid = current->pid;
423 list_add(&vma_entry->head, &dev->vmalist);
427 static void drm_vm_open(struct vm_area_struct *vma)
429 struct drm_file *priv = vma->vm_file->private_data;
430 struct drm_device *dev = priv->minor->dev;
432 mutex_lock(&dev->struct_mutex);
433 drm_vm_open_locked(vma);
434 mutex_unlock(&dev->struct_mutex);
438 * \c close method for all virtual memory types.
440 * \param vma virtual memory area.
442 * Search the \p vma private data entry in drm_device::vmalist, unlink it, and
445 static void drm_vm_close(struct vm_area_struct *vma)
447 struct drm_file *priv = vma->vm_file->private_data;
448 struct drm_device *dev = priv->minor->dev;
449 struct drm_vma_entry *pt, *temp;
451 DRM_DEBUG("0x%08lx,0x%08lx\n",
452 vma->vm_start, vma->vm_end - vma->vm_start);
453 atomic_dec(&dev->vma_count);
455 mutex_lock(&dev->struct_mutex);
456 list_for_each_entry_safe(pt, temp, &dev->vmalist, head) {
457 if (pt->vma == vma) {
459 drm_ctl_free(pt, sizeof(*pt), DRM_MEM_VMAS);
463 mutex_unlock(&dev->struct_mutex);
470 * \param file_priv DRM file private.
471 * \param vma virtual memory area.
472 * \return zero on success or a negative number on failure.
474 * Sets the virtual memory area operations structure to vm_dma_ops, the file
475 * pointer, and calls vm_open().
477 static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
479 struct drm_file *priv = filp->private_data;
480 struct drm_device *dev;
481 struct drm_device_dma *dma;
482 unsigned long length = vma->vm_end - vma->vm_start;
484 dev = priv->minor->dev;
486 DRM_DEBUG("start = 0x%lx, end = 0x%lx, page offset = 0x%lx\n",
487 vma->vm_start, vma->vm_end, vma->vm_pgoff);
489 /* Length must match exact page count */
490 if (!dma || (length >> PAGE_SHIFT) != dma->page_count) {
494 if (!capable(CAP_SYS_ADMIN) && (dma->flags & _DRM_DMA_USE_PCI_RO)) {
495 vma->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
496 #if defined(__i386__) || defined(__x86_64__)
497 pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
499 /* Ye gads this is ugly. With more thought
500 we could move this up higher and use
501 `protection_map' instead. */
505 (__pte(pgprot_val(vma->vm_page_prot)))));
509 vma->vm_ops = &drm_vm_dma_ops;
510 vma->vm_flags |= VM_RESERVED; /* Don't swap */
512 vma->vm_file = filp; /* Needed for drm_vm_open() */
513 drm_vm_open_locked(vma);
517 unsigned long drm_core_get_map_ofs(struct drm_map * map)
521 EXPORT_SYMBOL(drm_core_get_map_ofs);
523 unsigned long drm_core_get_reg_ofs(struct drm_device *dev)
526 return dev->hose->dense_mem_base - dev->hose->mem_space->start;
531 EXPORT_SYMBOL(drm_core_get_reg_ofs);
536 * \param file_priv DRM file private.
537 * \param vma virtual memory area.
538 * \return zero on success or a negative number on failure.
540 * If the virtual memory area has no offset associated with it then it's a DMA
541 * area, so calls mmap_dma(). Otherwise searches the map in drm_device::maplist,
542 * checks that the restricted flag is not set, sets the virtual memory operations
543 * according to the mapping type and remaps the pages. Finally sets the file
544 * pointer and calls vm_open().
546 static int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma)
548 struct drm_file *priv = filp->private_data;
549 struct drm_device *dev = priv->minor->dev;
550 struct drm_map *map = NULL;
551 unsigned long offset = 0;
552 struct drm_hash_item *hash;
554 DRM_DEBUG("start = 0x%lx, end = 0x%lx, page offset = 0x%lx\n",
555 vma->vm_start, vma->vm_end, vma->vm_pgoff);
557 if (!priv->authenticated)
560 /* We check for "dma". On Apple's UniNorth, it's valid to have
561 * the AGP mapped at physical address 0
568 || dev->agp->agp_info.device->vendor != PCI_VENDOR_ID_APPLE)
571 return drm_mmap_dma(filp, vma);
573 if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff, &hash)) {
574 DRM_ERROR("Could not find map\n");
578 map = drm_hash_entry(hash, struct drm_map_list, hash)->map;
579 if (!map || ((map->flags & _DRM_RESTRICTED) && !capable(CAP_SYS_ADMIN)))
582 /* Check for valid size. */
583 if (map->size < vma->vm_end - vma->vm_start)
586 if (!capable(CAP_SYS_ADMIN) && (map->flags & _DRM_READ_ONLY)) {
587 vma->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
588 #if defined(__i386__) || defined(__x86_64__)
589 pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
591 /* Ye gads this is ugly. With more thought
592 we could move this up higher and use
593 `protection_map' instead. */
597 (__pte(pgprot_val(vma->vm_page_prot)))));
603 if (drm_core_has_AGP(dev) && dev->agp->cant_use_aperture) {
605 * On some platforms we can't talk to bus dma address from the CPU, so for
606 * memory of type DRM_AGP, we'll deal with sorting out the real physical
607 * pages and mappings in nopage()
609 #if defined(__powerpc__)
610 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
612 vma->vm_ops = &drm_vm_ops;
615 /* fall through to _DRM_FRAME_BUFFER... */
616 case _DRM_FRAME_BUFFER:
618 offset = dev->driver->get_reg_ofs(dev);
619 vma->vm_flags |= VM_IO; /* not in core dump */
620 vma->vm_page_prot = drm_io_prot(map->type, vma);
621 if (io_remap_pfn_range(vma, vma->vm_start,
622 (map->offset + offset) >> PAGE_SHIFT,
623 vma->vm_end - vma->vm_start,
626 DRM_DEBUG(" Type = %d; start = 0x%lx, end = 0x%lx,"
629 vma->vm_start, vma->vm_end, map->offset + offset);
630 vma->vm_ops = &drm_vm_ops;
632 case _DRM_CONSISTENT:
633 /* Consistent memory is really like shared memory. But
634 * it's allocated in a different way, so avoid nopage */
635 if (remap_pfn_range(vma, vma->vm_start,
636 page_to_pfn(virt_to_page(map->handle)),
637 vma->vm_end - vma->vm_start, vma->vm_page_prot))
639 vma->vm_page_prot = drm_dma_prot(map->type, vma);
640 /* fall through to _DRM_SHM */
642 vma->vm_ops = &drm_vm_shm_ops;
643 vma->vm_private_data = (void *)map;
644 /* Don't let this area swap. Change when
645 DRM_KERNEL advisory is supported. */
646 vma->vm_flags |= VM_RESERVED;
648 case _DRM_SCATTER_GATHER:
649 vma->vm_ops = &drm_vm_sg_ops;
650 vma->vm_private_data = (void *)map;
651 vma->vm_flags |= VM_RESERVED;
652 vma->vm_page_prot = drm_dma_prot(map->type, vma);
655 return drm_bo_mmap_locked(vma, filp, map);
657 return -EINVAL; /* This should never happen. */
659 vma->vm_flags |= VM_RESERVED; /* Don't swap */
661 vma->vm_file = filp; /* Needed for drm_vm_open() */
662 drm_vm_open_locked(vma);
666 int drm_mmap(struct file *filp, struct vm_area_struct *vma)
668 struct drm_file *priv = filp->private_data;
669 struct drm_device *dev = priv->minor->dev;
672 mutex_lock(&dev->struct_mutex);
673 ret = drm_mmap_locked(filp, vma);
674 mutex_unlock(&dev->struct_mutex);
678 EXPORT_SYMBOL(drm_mmap);
681 * buffer object vm functions.
685 * \c Pagefault method for buffer objects.
687 * \param vma Virtual memory area.
688 * \param address File offset.
689 * \return Error or refault. The pfn is manually inserted.
691 * It's important that pfns are inserted while holding the bo->mutex lock.
692 * otherwise we might race with unmap_mapping_range() which is always
693 * called with the bo->mutex lock held.
695 * We're modifying the page attribute bits of the vma->vm_page_prot field,
696 * without holding the mmap_sem in write mode. Only in read mode.
697 * These bits are not used by the mm subsystem code, and we consider them
698 * protected by the bo->mutex lock.
701 #ifdef DRM_FULL_MM_COMPAT
702 static unsigned long drm_bo_vm_nopfn(struct vm_area_struct *vma,
703 unsigned long address)
705 struct drm_buffer_object *bo = (struct drm_buffer_object *) vma->vm_private_data;
706 unsigned long page_offset;
707 struct page *page = NULL;
709 struct drm_device *dev;
712 unsigned long bus_base;
713 unsigned long bus_offset;
714 unsigned long bus_size;
715 unsigned long ret = NOPFN_REFAULT;
717 if (address > vma->vm_end)
721 err = drm_bo_read_lock(&dev->bm.bm_lock, 1);
723 return NOPFN_REFAULT;
725 err = mutex_lock_interruptible(&bo->mutex);
727 drm_bo_read_unlock(&dev->bm.bm_lock);
728 return NOPFN_REFAULT;
731 err = drm_bo_wait(bo, 0, 1, 0, 1);
733 ret = (err != -EAGAIN) ? NOPFN_SIGBUS : NOPFN_REFAULT;
734 bo->priv_flags &= ~_DRM_BO_FLAG_UNLOCKED;
738 bo->priv_flags &= ~_DRM_BO_FLAG_UNLOCKED;
741 * If buffer happens to be in a non-mappable location,
742 * move it to a mappable.
745 if (!(bo->mem.flags & DRM_BO_FLAG_MAPPABLE)) {
746 uint32_t new_flags = bo->mem.proposed_flags |
747 DRM_BO_FLAG_MAPPABLE |
748 DRM_BO_FLAG_FORCE_MAPPABLE;
749 err = drm_bo_move_buffer(bo, new_flags, 0, 0);
751 ret = (err != -EAGAIN) ? NOPFN_SIGBUS : NOPFN_REFAULT;
756 err = drm_bo_pci_offset(dev, &bo->mem, &bus_base, &bus_offset,
764 page_offset = (address - vma->vm_start) >> PAGE_SHIFT;
767 struct drm_mem_type_manager *man = &dev->bm.man[bo->mem.mem_type];
769 pfn = ((bus_base + bus_offset) >> PAGE_SHIFT) + page_offset;
770 vma->vm_page_prot = drm_io_prot(man->drm_bus_maptype, vma);
774 drm_ttm_fixup_caching(ttm);
775 page = drm_ttm_get_page(ttm, page_offset);
780 pfn = page_to_pfn(page);
781 vma->vm_page_prot = (bo->mem.flags & DRM_BO_FLAG_CACHED) ?
782 vm_get_page_prot(vma->vm_flags) :
783 drm_io_prot(_DRM_TTM, vma);
786 err = vm_insert_pfn(vma, address, pfn);
788 ret = (err != -EAGAIN) ? NOPFN_OOM : NOPFN_REFAULT;
792 BUG_ON(bo->priv_flags & _DRM_BO_FLAG_UNLOCKED);
793 mutex_unlock(&bo->mutex);
794 drm_bo_read_unlock(&dev->bm.bm_lock);
799 static void drm_bo_vm_open_locked(struct vm_area_struct *vma)
801 struct drm_buffer_object *bo = (struct drm_buffer_object *) vma->vm_private_data;
803 drm_vm_open_locked(vma);
804 atomic_inc(&bo->usage);
805 #ifdef DRM_ODD_MM_COMPAT
806 drm_bo_add_vma(bo, vma);
811 * \c vma open method for buffer objects.
813 * \param vma virtual memory area.
816 static void drm_bo_vm_open(struct vm_area_struct *vma)
818 struct drm_buffer_object *bo = (struct drm_buffer_object *) vma->vm_private_data;
819 struct drm_device *dev = bo->dev;
821 mutex_lock(&dev->struct_mutex);
822 drm_bo_vm_open_locked(vma);
823 mutex_unlock(&dev->struct_mutex);
827 * \c vma close method for buffer objects.
829 * \param vma virtual memory area.
832 static void drm_bo_vm_close(struct vm_area_struct *vma)
834 struct drm_buffer_object *bo = (struct drm_buffer_object *) vma->vm_private_data;
835 struct drm_device *dev = bo->dev;
839 mutex_lock(&dev->struct_mutex);
840 #ifdef DRM_ODD_MM_COMPAT
841 drm_bo_delete_vma(bo, vma);
843 drm_bo_usage_deref_locked((struct drm_buffer_object **)
844 &vma->vm_private_data);
845 mutex_unlock(&dev->struct_mutex);
850 static struct vm_operations_struct drm_bo_vm_ops = {
851 #ifdef DRM_FULL_MM_COMPAT
852 .nopfn = drm_bo_vm_nopfn,
854 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19))
855 .nopfn = drm_bo_vm_nopfn,
857 .nopage = drm_bo_vm_nopage,
860 .open = drm_bo_vm_open,
861 .close = drm_bo_vm_close,
865 * mmap buffer object memory.
867 * \param vma virtual memory area.
868 * \param file_priv DRM file private.
869 * \param map The buffer object drm map.
870 * \return zero on success or a negative number on failure.
873 int drm_bo_mmap_locked(struct vm_area_struct *vma,
875 drm_local_map_t *map)
877 vma->vm_ops = &drm_bo_vm_ops;
878 vma->vm_private_data = map->handle;
880 vma->vm_flags |= VM_RESERVED | VM_IO;
881 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19))
882 vma->vm_flags |= VM_PFNMAP;
884 drm_bo_vm_open_locked(vma);
885 #ifdef DRM_ODD_MM_COMPAT
886 drm_bo_map_bound(vma);