summaryrefslogtreecommitdiff
path: root/linux-core/drm_compat.c
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2008-07-31 13:12:36 +1000
committerDave Airlie <airlied@redhat.com>2008-07-31 13:11:28 +1000
commit55761b2fe706f8f68ca3a8827b950fd01af1650b (patch)
tree2475c040590933a7f582ea95538e48816768bd49 /linux-core/drm_compat.c
parent9b8d71b5eb09857b07409731d3de182751f712a2 (diff)
drm: add fault handler support so as to be more like possible upstream
(cherry picked from commit 10d5b037b85706037df89bf0275436797e4eb559)
Diffstat (limited to 'linux-core/drm_compat.c')
-rw-r--r--linux-core/drm_compat.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/linux-core/drm_compat.c b/linux-core/drm_compat.c
index aa825f32..d06b9d24 100644
--- a/linux-core/drm_compat.c
+++ b/linux-core/drm_compat.c
@@ -806,3 +806,102 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type,
EXPORT_SYMBOL(kmap_atomic_prot_pfn);
#endif
+#ifdef DRM_FULL_MM_COMPAT
+#ifdef DRM_NO_FAULT
+unsigned long drm_bo_vm_nopfn(struct vm_area_struct *vma,
+ unsigned long 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;
+ unsigned long ret = NOPFN_REFAULT;
+
+ if (address > vma->vm_end)
+ return NOPFN_SIGBUS;
+
+ dev = bo->dev;
+ err = drm_bo_read_lock(&dev->bm.bm_lock, 1);
+ if (err)
+ return NOPFN_REFAULT;
+
+ err = mutex_lock_interruptible(&bo->mutex);
+ if (err) {
+ drm_bo_read_unlock(&dev->bm.bm_lock);
+ return NOPFN_REFAULT;
+ }
+
+ err = drm_bo_wait(bo, 0, 1, 0, 1);
+ if (err) {
+ ret = (err != -EAGAIN) ? NOPFN_SIGBUS : NOPFN_REFAULT;
+ bo->priv_flags &= ~_DRM_BO_FLAG_UNLOCKED;
+ goto out_unlock;
+ }
+
+ bo->priv_flags &= ~_DRM_BO_FLAG_UNLOCKED;
+
+ /*
+ * If buffer happens to be in a non-mappable location,
+ * move it to a mappable.
+ */
+
+ if (!(bo->mem.flags & DRM_BO_FLAG_MAPPABLE)) {
+ uint32_t new_flags = bo->mem.proposed_flags |
+ DRM_BO_FLAG_MAPPABLE |
+ DRM_BO_FLAG_FORCE_MAPPABLE;
+ err = drm_bo_move_buffer(bo, new_flags, 0, 0);
+ if (err) {
+ ret = (err != -EAGAIN) ? NOPFN_SIGBUS : NOPFN_REFAULT;
+ goto out_unlock;
+ }
+ }
+
+ err = drm_bo_pci_offset(dev, &bo->mem, &bus_base, &bus_offset,
+ &bus_size);
+
+ if (err) {
+ ret = NOPFN_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) {
+ ret = NOPFN_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) {
+ ret = (err != -EAGAIN) ? NOPFN_OOM : NOPFN_REFAULT;
+ goto out_unlock;
+ }
+out_unlock:
+ BUG_ON(bo->priv_flags & _DRM_BO_FLAG_UNLOCKED);
+ mutex_unlock(&bo->mutex);
+ drm_bo_read_unlock(&dev->bm.bm_lock);
+ return ret;
+}
+#endif
+#endif