summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/mm_basic.c (renamed from tests/mmfs_basic.c)33
-rw-r--r--tests/mm_mmap.c (renamed from tests/mmfs_mmap.c)40
-rw-r--r--tests/mm_readwrite.c (renamed from tests/mmfs_readwrite.c)34
4 files changed, 50 insertions, 63 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 67cb034d..f997e26e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,9 +23,9 @@ TESTS = auth \
lock \
setversion \
updatedraw \
- mmfs_basic \
- mmfs_readwrite \
- mmfs_mmap
+ mm_basic \
+ mm_readwrite \
+ mm_mmap
EXTRA_PROGRAMS = $(TESTS)
CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES)
diff --git a/tests/mmfs_basic.c b/tests/mm_basic.c
index c6975b0b..94240ee1 100644
--- a/tests/mmfs_basic.c
+++ b/tests/mm_basic.c
@@ -33,30 +33,18 @@
#include <inttypes.h>
#include <errno.h>
#include <sys/stat.h>
-#include "mmfs.h"
+#include "drm.h"
static void
test_bad_unref(int fd)
{
- struct mmfs_unreference_args unref;
+ struct drm_mm_unreference_args unref;
int ret;
printf("Testing error return on bad unreference ioctl.\n");
unref.handle = 0x10101010;
- ret = ioctl(fd, MMFS_IOCTL_UNREFERENCE, &unref);
-
- assert(ret == -1 && errno == EINVAL);
-}
-
-static void
-test_bad_ioctl(int fd)
-{
- int ret;
-
- printf("Testing error return on bad ioctl.\n");
-
- ret = ioctl(fd, _IO(MMFS_IOCTL_BASE, 0xf0), 0);
+ ret = ioctl(fd, DRM_IOCTL_MM_UNREFERENCE, &unref);
assert(ret == -1 && errno == EINVAL);
}
@@ -64,32 +52,32 @@ test_bad_ioctl(int fd)
static void
test_alloc_unref(int fd)
{
- struct mmfs_alloc_args alloc;
- struct mmfs_unreference_args unref;
+ struct drm_mm_alloc_args alloc;
+ struct drm_mm_unreference_args unref;
int ret;
printf("Testing allocating and unreferencing an object.\n");
memset(&alloc, 0, sizeof(alloc));
alloc.size = 16 * 1024;
- ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc);
+ ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc);
assert(ret == 0);
unref.handle = alloc.handle;
- ret = ioctl(fd, MMFS_IOCTL_UNREFERENCE, &unref);
+ ret = ioctl(fd, DRM_IOCTL_MM_UNREFERENCE, &unref);
}
static void
test_alloc_close(int fd)
{
- struct mmfs_alloc_args alloc;
+ struct drm_mm_alloc_args alloc;
int ret;
printf("Testing closing with an object allocated.\n");
memset(&alloc, 0, sizeof(alloc));
alloc.size = 16 * 1024;
- ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc);
+ ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc);
assert(ret == 0);
close(fd);
@@ -99,9 +87,8 @@ int main(int argc, char **argv)
{
int fd;
- fd = open_mmfs_device();
+ fd = drm_open_any();
- test_bad_ioctl(fd);
test_bad_unref(fd);
test_alloc_unref(fd);
test_alloc_close(fd);
diff --git a/tests/mmfs_mmap.c b/tests/mm_mmap.c
index 3cb6a853..e5c4538a 100644
--- a/tests/mmfs_mmap.c
+++ b/tests/mm_mmap.c
@@ -33,13 +33,13 @@
#include <inttypes.h>
#include <errno.h>
#include <sys/stat.h>
-#include "mmfs.h"
+#include "drm.h"
-#define MMFS_BUFFER_SIZE 16384
+#define OBJECT_SIZE 16384
int do_read(int fd, int handle, void *buf, int offset, int size)
{
- struct mmfs_pread_args read;
+ struct drm_mm_pread_args read;
/* Ensure that we don't have any convenient data in buf in case
* we fail.
@@ -52,12 +52,12 @@ int do_read(int fd, int handle, void *buf, int offset, int size)
read.size = size;
read.offset = offset;
- return ioctl(fd, MMFS_IOCTL_PREAD, &read);
+ return ioctl(fd, DRM_IOCTL_MM_PREAD, &read);
}
int do_write(int fd, int handle, void *buf, int offset, int size)
{
- struct mmfs_pwrite_args write;
+ struct drm_mm_pwrite_args write;
memset(&write, 0, sizeof(write));
write.handle = handle;
@@ -65,41 +65,41 @@ int do_write(int fd, int handle, void *buf, int offset, int size)
write.size = size;
write.offset = offset;
- return ioctl(fd, MMFS_IOCTL_PWRITE, &write);
+ return ioctl(fd, DRM_IOCTL_MM_PWRITE, &write);
}
int main(int argc, char **argv)
{
int fd;
- struct mmfs_alloc_args alloc;
- struct mmfs_mmap_args mmap;
- struct mmfs_unreference_args unref;
- uint8_t expected[MMFS_BUFFER_SIZE];
- uint8_t buf[MMFS_BUFFER_SIZE];
+ struct drm_mm_alloc_args alloc;
+ struct drm_mm_mmap_args mmap;
+ struct drm_mm_unreference_args unref;
+ uint8_t expected[OBJECT_SIZE];
+ uint8_t buf[OBJECT_SIZE];
int ret;
int handle;
- fd = open_mmfs_device();
+ fd = drm_open_any();
memset(&mmap, 0, sizeof(mmap));
mmap.handle = 0x10101010;
mmap.offset = 0;
mmap.size = 4096;
printf("Testing mmaping of bad object.\n");
- ret = ioctl(fd, MMFS_IOCTL_MMAP, &mmap);
+ ret = ioctl(fd, DRM_IOCTL_MM_MMAP, &mmap);
assert(ret == -1 && errno == EINVAL);
memset(&alloc, 0, sizeof(alloc));
- alloc.size = MMFS_BUFFER_SIZE;
- ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc);
+ alloc.size = OBJECT_SIZE;
+ ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc);
assert(ret == 0);
handle = alloc.handle;
printf("Testing mmaping of newly allocated object.\n");
mmap.handle = handle;
mmap.offset = 0;
- mmap.size = MMFS_BUFFER_SIZE;
- ret = ioctl(fd, MMFS_IOCTL_MMAP, &mmap);
+ mmap.size = OBJECT_SIZE;
+ ret = ioctl(fd, DRM_IOCTL_MM_MMAP, &mmap);
assert(ret == 0);
printf("Testing contents of newly allocated object.\n");
@@ -110,18 +110,18 @@ int main(int argc, char **argv)
memset(buf, 0, sizeof(buf));
memset(buf + 1024, 0x01, 1024);
memset(expected + 1024, 0x01, 1024);
- ret = do_write(fd, handle, buf, 0, MMFS_BUFFER_SIZE);
+ ret = do_write(fd, handle, buf, 0, OBJECT_SIZE);
assert(ret == 0);
assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0);
printf("Testing that mapping stays after unreference\n");
unref.handle = handle;
- ret = ioctl(fd, MMFS_IOCTL_UNREFERENCE, &unref);
+ ret = ioctl(fd, DRM_IOCTL_MM_UNREFERENCE, &unref);
assert(ret == 0);
assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0);
printf("Testing unmapping\n");
- munmap(mmap.addr, MMFS_BUFFER_SIZE);
+ munmap(mmap.addr, OBJECT_SIZE);
close(fd);
diff --git a/tests/mmfs_readwrite.c b/tests/mm_readwrite.c
index 09d1967d..a778231a 100644
--- a/tests/mmfs_readwrite.c
+++ b/tests/mm_readwrite.c
@@ -33,13 +33,13 @@
#include <inttypes.h>
#include <errno.h>
#include <sys/stat.h>
-#include "mmfs.h"
+#include "drm.h"
-#define MMFS_BUFFER_SIZE 16384
+#define OBJECT_SIZE 16384
int do_read(int fd, int handle, void *buf, int offset, int size)
{
- struct mmfs_pread_args read;
+ struct drm_mm_pread_args read;
/* Ensure that we don't have any convenient data in buf in case
* we fail.
@@ -52,12 +52,12 @@ int do_read(int fd, int handle, void *buf, int offset, int size)
read.size = size;
read.offset = offset;
- return ioctl(fd, MMFS_IOCTL_PREAD, &read);
+ return ioctl(fd, DRM_IOCTL_MM_PREAD, &read);
}
int do_write(int fd, int handle, void *buf, int offset, int size)
{
- struct mmfs_pwrite_args write;
+ struct drm_mm_pwrite_args write;
memset(&write, 0, sizeof(write));
write.handle = handle;
@@ -65,43 +65,43 @@ int do_write(int fd, int handle, void *buf, int offset, int size)
write.size = size;
write.offset = offset;
- return ioctl(fd, MMFS_IOCTL_PWRITE, &write);
+ return ioctl(fd, DRM_IOCTL_MM_PWRITE, &write);
}
int main(int argc, char **argv)
{
int fd;
- struct mmfs_alloc_args alloc;
- uint8_t expected[MMFS_BUFFER_SIZE];
- uint8_t buf[MMFS_BUFFER_SIZE];
+ struct drm_mm_alloc_args alloc;
+ uint8_t expected[OBJECT_SIZE];
+ uint8_t buf[OBJECT_SIZE];
int ret;
int handle;
- fd = open_mmfs_device();
+ fd = drm_open_any();
memset(&alloc, 0, sizeof(alloc));
- alloc.size = MMFS_BUFFER_SIZE;
- ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc);
+ alloc.size = OBJECT_SIZE;
+ ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc);
assert(ret == 0);
handle = alloc.handle;
printf("Testing contents of newly allocated object.\n");
- ret = do_read(fd, handle, buf, 0, MMFS_BUFFER_SIZE);
+ ret = do_read(fd, handle, buf, 0, OBJECT_SIZE);
assert(ret == 0);
memset(&expected, 0, sizeof(expected));
assert(memcmp(expected, buf, sizeof(expected)) == 0);
printf("Testing read beyond end of buffer.\n");
- ret = do_read(fd, handle, buf, MMFS_BUFFER_SIZE / 2, MMFS_BUFFER_SIZE);
+ ret = do_read(fd, handle, buf, OBJECT_SIZE / 2, OBJECT_SIZE);
assert(ret == -1 && errno == EINVAL);
printf("Testing full write of buffer\n");
memset(buf, 0, sizeof(buf));
memset(buf + 1024, 0x01, 1024);
memset(expected + 1024, 0x01, 1024);
- ret = do_write(fd, handle, buf, 0, MMFS_BUFFER_SIZE);
+ ret = do_write(fd, handle, buf, 0, OBJECT_SIZE);
assert(ret == 0);
- ret = do_read(fd, handle, buf, 0, MMFS_BUFFER_SIZE);
+ ret = do_read(fd, handle, buf, 0, OBJECT_SIZE);
assert(ret == 0);
assert(memcmp(buf, expected, sizeof(buf)) == 0);
@@ -110,7 +110,7 @@ int main(int argc, char **argv)
memset(expected + 4096, 0x02, 1024);
ret = do_write(fd, handle, buf + 4096, 4096, 1024);
assert(ret == 0);
- ret = do_read(fd, handle, buf, 0, MMFS_BUFFER_SIZE);
+ ret = do_read(fd, handle, buf, 0, OBJECT_SIZE);
assert(ret == 0);
assert(memcmp(buf, expected, sizeof(buf)) == 0);
>607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
/**************************************************************************
 *
 * This kernel module is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 **************************************************************************/
/*
 * This code provides access to unexported mm kernel features. It is necessary
 * to use the new DRM memory manager code with kernels that don't support it
 * directly.
 *
 * Authors: Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
 *          Linux kernel mm subsystem authors.
 *          (Most code taken from there).
 */

#include "drmP.h"

#if defined(CONFIG_X86) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))

/*
 * These have bad performance in the AGP module for the indicated kernel versions.
 */

int drm_map_page_into_agp(struct page *page)
{
        int i;
        i = change_page_attr(page, 1, PAGE_KERNEL_NOCACHE);
        /* Caller's responsibility to call global_flush_tlb() for
         * performance reasons */
        return i;
}

int drm_unmap_page_from_agp(struct page *page)
{
        int i;
        i = change_page_attr(page, 1, PAGE_KERNEL);
        /* Caller's responsibility to call global_flush_tlb() for
         * performance reasons */
        return i;
}
#endif


#if  (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))

/*
 * The protection map was exported in 2.6.19
 */

pgprot_t vm_get_page_prot(unsigned long vm_flags)
{
#ifdef MODULE
	static pgprot_t drm_protection_map[16] = {
		__P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
		__S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
	};

	return drm_protection_map[vm_flags & 0x0F];
#else
	extern pgprot_t protection_map[];
	return protection_map[vm_flags & 0x0F];
#endif
};
#endif


#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))

/*
 * vm code for kernels below 2.6.15 in which version a major vm write
 * occured. This implement a simple straightforward
 * version similar to what's going to be
 * in kernel 2.6.19+
 * Kernels below 2.6.15 use nopage whereas 2.6.19 and upwards use
 * nopfn.
 */

static struct {
	spinlock_t lock;
	struct page *dummy_page;
	atomic_t present;
} drm_np_retry =
{SPIN_LOCK_UNLOCKED, NOPAGE_OOM, ATOMIC_INIT(0)};


static struct page *drm_bo_vm_fault(struct vm_area_struct *vma,
				    struct fault_data *data);


struct page * get_nopage_retry(void)
{
	if (atomic_read(&drm_np_retry.present) == 0) {
		struct page *page = alloc_page(GFP_KERNEL);
		if (!page)
			return NOPAGE_OOM;
		spin_lock(&drm_np_retry.lock);
		drm_np_retry.dummy_page = page;
		atomic_set(&drm_np_retry.present,1);
		spin_unlock(&drm_np_retry.lock);
	}
	get_page(drm_np_retry.dummy_page);
	return drm_np_retry.dummy_page;
}

void free_nopage_retry(void)
{
	if (atomic_read(&drm_np_retry.present) == 1) {
		spin_lock(&drm_np_retry.lock);
		__free_page(drm_np_retry.dummy_page);
		drm_np_retry.dummy_page = NULL;
		atomic_set(&drm_np_retry.present, 0);
		spin_unlock(&drm_np_retry.lock);
	}
}

struct page *drm_bo_vm_nopage(struct vm_area_struct *vma,
			       unsigned long address,
			       int *type)
{
	struct fault_data data;

	if (type)
		*type = VM_FAULT_MINOR;

	data.address = address;
	data.vma = vma;
	drm_bo_vm_fault(vma, &data);
	switch (data.type) {
	case VM_FAULT_OOM:
		return NOPAGE_OOM;
	case VM_FAULT_SIGBUS:
		return NOPAGE_SIGBUS;
	default:
		break;
	}

	return NOPAGE_REFAULT;
}

#endif

#if !defined(DRM_FULL_MM_COMPAT) && \
  ((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)) || \
   (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)))

static int drm_pte_is_clear(struct vm_area_struct *vma,
			    unsigned long addr)
{
	struct mm_struct *mm = vma->vm_mm;
	int ret = 1;
	pte_t *pte;
	pmd_t *pmd;
	pud_t *pud;
	pgd_t *pgd;

	spin_lock(&mm->page_table_lock);
	pgd = pgd_offset(mm, addr);
	if (pgd_none(*pgd))
		goto unlock;
	pud = pud_offset(pgd, addr);
        if (pud_none(*pud))
		goto unlock;
	pmd = pmd_offset(pud, addr);
	if (pmd_none(*pmd))
		goto unlock;
	pte = pte_offset_map(pmd, addr);
	if (!pte)
		goto unlock;
	ret = pte_none(*pte);
	pte_unmap(pte);
 unlock:
	spin_unlock(&mm->page_table_lock);
	return ret;
}

static int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
		  unsigned long pfn)
{
	int ret;
	if (!drm_pte_is_clear(vma, addr))
		return -EBUSY;

	ret = io_remap_pfn_range(vma, addr, pfn, PAGE_SIZE, vma->vm_page_prot);
	return ret;
}


static struct page *drm_bo_vm_fault(struct vm_area_struct *vma,
				    struct fault_data *data)
{
	unsigned long address = data->address;
	struct drm_buffer_object *bo = (struct drm_buffer_object *) vma->vm_private_data;
	unsigned long page_offset;
	struct page *page = NULL;
	struct drm_ttm *ttm;
	struct drm_device *dev;
	unsigned long pfn;
	int err;
	unsigned long bus_base;
	unsigned long bus_offset;
	unsigned long bus_size;

	dev = bo->dev;
	drm_bo_read_lock(&dev->bm.bm_lock, 0);

	mutex_lock(&bo->mutex);

	err = drm_bo_wait(bo, 0, 1, 0, 1);
	if (err) {
		data->type = (err == -EAGAIN) ?
			VM_FAULT_MINOR : VM_FAULT_SIGBUS;
		goto out_unlock;
	}


	/*
	 * If buffer happens to be in a non-mappable location,
	 * move it to a mappable.
	 */

	if (!(bo->mem.flags & DRM_BO_FLAG_MAPPABLE)) {
		unsigned long _end = jiffies + 3*DRM_HZ;
		uint32_t new_mask = bo->mem.proposed_flags |
			DRM_BO_FLAG_MAPPABLE |
			DRM_BO_FLAG_FORCE_MAPPABLE;

		do {
			err = drm_bo_move_buffer(bo, new_mask, 0, 0);
		} while((err == -EAGAIN) && !time_after_eq(jiffies, _end));

		if (err) {
			DRM_ERROR("Timeout moving buffer to mappable location.\n");
			data->type = VM_FAULT_SIGBUS;
			goto out_unlock;
		}
	}

	if (address > vma->vm_end) {
		data->type = VM_FAULT_SIGBUS;
		goto out_unlock;
	}

	dev = bo->dev;
	err = drm_bo_pci_offset(dev, &bo->mem, &bus_base, &bus_offset,
				&bus_size);

	if (err) {
		data->type = VM_FAULT_SIGBUS;
		goto out_unlock;
	}

	page_offset = (address - vma->vm_start) >> PAGE_SHIFT;

	if (bus_size) {
		struct drm_mem_type_manager *man = &dev->bm.man[bo->mem.mem_type];

		pfn = ((bus_base + bus_offset) >> PAGE_SHIFT) + page_offset;
		vma->vm_page_prot = drm_io_prot(man->drm_bus_maptype, vma);
	} else {
		ttm = bo->ttm;

		drm_ttm_fixup_caching(ttm);
		page = drm_ttm_get_page(ttm, page_offset);
		if (!page) {
			data->type = VM_FAULT_OOM;
			goto out_unlock;
		}
		pfn = page_to_pfn(page);
		vma->vm_page_prot = (bo->mem.flags & DRM_BO_FLAG_CACHED) ?
			vm_get_page_prot(vma->vm_flags) :
			drm_io_prot(_DRM_TTM, vma);
	}

	err = vm_insert_pfn(vma, address, pfn);

	if (!err || err == -EBUSY)
		data->type = VM_FAULT_MINOR;
	else
		data->type = VM_FAULT_OOM;
out_unlock:
	mutex_unlock(&bo->mutex);
	drm_bo_read_unlock(&dev->bm.bm_lock);
	return NULL;
}

#endif

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)) && \
  !defined(DRM_FULL_MM_COMPAT)

/**
 */

unsigned long drm_bo_vm_nopfn(struct vm_area_struct * vma,
			   unsigned long address)
{
	struct fault_data data;
	data.address = address;

	(void) drm_bo_vm_fault(vma, &data);
	if (data.type == VM_FAULT_OOM)
		return NOPFN_OOM;
	else if (data.type == VM_FAULT_SIGBUS)
		return NOPFN_SIGBUS;

	/*
	 * pfn already set.
	 */

	return 0;
}
#endif


#ifdef DRM_ODD_MM_COMPAT

/*
 * VM compatibility code for 2.6.15-2.6.18. This code implements a complicated
 * workaround for a single BUG statement in do_no_page in these versions. The
 * tricky thing is that we need to take the mmap_sem in exclusive mode for _all_
 * vmas mapping the ttm, before dev->struct_mutex is taken. The way we do this is to
 * check first take the dev->struct_mutex, and then trylock all mmap_sems. If this
 * fails for a single mmap_sem, we have to release all sems and the dev->struct_mutex,
 * release the cpu and retry. We also need to keep track of all vmas mapping the ttm.
 * phew.
 */

typedef struct p_mm_entry {
	struct list_head head;
	struct mm_struct *mm;
	atomic_t refcount;
        int locked;
} p_mm_entry_t;

typedef struct vma_entry {
	struct list_head head;
	struct vm_area_struct *vma;
} vma_entry_t;


struct page *drm_bo_vm_nopage(struct vm_area_struct *vma,
			       unsigned long address,
			       int *type)
{
	struct drm_buffer_object *bo = (struct drm_buffer_object *) vma->vm_private_data;
	unsigned long page_offset;
	struct page *page;
	struct drm_ttm *ttm;
	struct drm_device *dev;

	mutex_lock(&bo->mutex);

	if (type)
		*type = VM_FAULT_MINOR;

	if (address > vma->vm_end) {
		page = NOPAGE_SIGBUS;
		goto out_unlock;
	}

	dev = bo->dev;

	if (drm_mem_reg_is_pci(dev, &bo->mem)) {
		DRM_ERROR("Invalid compat nopage.\n");
		page = NOPAGE_SIGBUS;
		goto out_unlock;
	}

	ttm = bo->ttm;
	drm_ttm_fixup_caching(ttm);
	page_offset = (address - vma->vm_start) >> PAGE_SHIFT;
	page = drm_ttm_get_page(ttm, page_offset);
	if (!page) {
		page = NOPAGE_OOM;
		goto out_unlock;
	}

	get_page(page);
out_unlock:
	mutex_unlock(&bo->mutex);
	return page;
}




int drm_bo_map_bound(struct vm_area_struct *vma)
{
	struct drm_buffer_object *bo = (struct drm_buffer_object *)vma->vm_private_data;
	int ret = 0;
	unsigned long bus_base;
	unsigned long bus_offset;
	unsigned long bus_size;

	ret = drm_bo_pci_offset(bo->dev, &bo->mem, &bus_base,
				&bus_offset, &bus_size);
	BUG_ON(ret);

	if (bus_size) {
		struct drm_mem_type_manager *man = &bo->dev->bm.man[bo->mem.mem_type];
		unsigned long pfn = (bus_base + bus_offset) >> PAGE_SHIFT;
		pgprot_t pgprot = drm_io_prot(man->drm_bus_maptype, vma);
		ret = io_remap_pfn_range(vma, vma->vm_start, pfn,
					 vma->vm_end - vma->vm_start,
					 pgprot);
	}

	return ret;
}


int drm_bo_add_vma(struct drm_buffer_object * bo, struct vm_area_struct *vma)
{
	p_mm_entry_t *entry, *n_entry;
	vma_entry_t *v_entry;
	struct mm_struct *mm = vma->vm_mm;

	v_entry = drm_ctl_alloc(sizeof(*v_entry), DRM_MEM_BUFOBJ);
	if (!v_entry) {
		DRM_ERROR("Allocation of vma pointer entry failed\n");
		return -ENOMEM;
	}
	v_entry->vma = vma;

	list_add_tail(&v_entry->head, &bo->vma_list);

	list_for_each_entry(entry, &bo->p_mm_list, head) {
		if (mm == entry->mm) {
			atomic_inc(&entry->refcount);
			return 0;
		} else if ((unsigned long)mm < (unsigned long)entry->mm) ;
	}