summaryrefslogtreecommitdiff
path: root/linux-core/drm_compat.c
diff options
context:
space:
mode:
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