19
19
#include "i915_gem_mman.h"
20
20
#include "i915_trace.h"
21
21
#include "i915_user_extensions.h"
22
+ #include "i915_gem_ttm.h"
22
23
#include "i915_vma.h"
23
24
24
25
static inline bool
@@ -623,6 +624,8 @@ mmap_offset_attach(struct drm_i915_gem_object *obj,
623
624
struct i915_mmap_offset * mmo ;
624
625
int err ;
625
626
627
+ GEM_BUG_ON (obj -> ops -> mmap_offset || obj -> ops -> mmap_ops );
628
+
626
629
mmo = lookup_mmo (obj , mmap_type );
627
630
if (mmo )
628
631
goto out ;
@@ -665,40 +668,47 @@ mmap_offset_attach(struct drm_i915_gem_object *obj,
665
668
}
666
669
667
670
static int
668
- __assign_mmap_offset (struct drm_file * file ,
669
- u32 handle ,
671
+ __assign_mmap_offset (struct drm_i915_gem_object * obj ,
670
672
enum i915_mmap_type mmap_type ,
671
- u64 * offset )
673
+ u64 * offset , struct drm_file * file )
672
674
{
673
- struct drm_i915_gem_object * obj ;
674
675
struct i915_mmap_offset * mmo ;
675
- int err ;
676
676
677
- obj = i915_gem_object_lookup (file , handle );
678
- if (!obj )
679
- return - ENOENT ;
677
+ if (i915_gem_object_never_mmap (obj ))
678
+ return - ENODEV ;
680
679
681
- if (i915_gem_object_never_mmap ( obj )) {
682
- err = - ENODEV ;
683
- goto out ;
680
+ if (obj -> ops -> mmap_offset ) {
681
+ * offset = obj -> ops -> mmap_offset ( obj ) ;
682
+ return 0 ;
684
683
}
685
684
686
685
if (mmap_type != I915_MMAP_TYPE_GTT &&
687
686
!i915_gem_object_has_struct_page (obj ) &&
688
- !i915_gem_object_type_has (obj , I915_GEM_OBJECT_HAS_IOMEM )) {
689
- err = - ENODEV ;
690
- goto out ;
691
- }
687
+ !i915_gem_object_type_has (obj , I915_GEM_OBJECT_HAS_IOMEM ))
688
+ return - ENODEV ;
692
689
693
690
mmo = mmap_offset_attach (obj , mmap_type , file );
694
- if (IS_ERR (mmo )) {
695
- err = PTR_ERR (mmo );
696
- goto out ;
697
- }
691
+ if (IS_ERR (mmo ))
692
+ return PTR_ERR (mmo );
698
693
699
694
* offset = drm_vma_node_offset_addr (& mmo -> vma_node );
700
- err = 0 ;
701
- out :
695
+ return 0 ;
696
+ }
697
+
698
+ static int
699
+ __assign_mmap_offset_handle (struct drm_file * file ,
700
+ u32 handle ,
701
+ enum i915_mmap_type mmap_type ,
702
+ u64 * offset )
703
+ {
704
+ struct drm_i915_gem_object * obj ;
705
+ int err ;
706
+
707
+ obj = i915_gem_object_lookup (file , handle );
708
+ if (!obj )
709
+ return - ENOENT ;
710
+
711
+ err = __assign_mmap_offset (obj , mmap_type , offset , file );
702
712
i915_gem_object_put (obj );
703
713
return err ;
704
714
}
@@ -718,7 +728,7 @@ i915_gem_dumb_mmap_offset(struct drm_file *file,
718
728
else
719
729
mmap_type = I915_MMAP_TYPE_GTT ;
720
730
721
- return __assign_mmap_offset (file , handle , mmap_type , offset );
731
+ return __assign_mmap_offset_handle (file , handle , mmap_type , offset );
722
732
}
723
733
724
734
/**
@@ -786,7 +796,7 @@ i915_gem_mmap_offset_ioctl(struct drm_device *dev, void *data,
786
796
return - EINVAL ;
787
797
}
788
798
789
- return __assign_mmap_offset (file , args -> handle , type , & args -> offset );
799
+ return __assign_mmap_offset_handle (file , args -> handle , type , & args -> offset );
790
800
}
791
801
792
802
static void vm_open (struct vm_area_struct * vma )
@@ -890,8 +900,18 @@ int i915_gem_mmap(struct file *filp, struct vm_area_struct *vma)
890
900
* destroyed and will be invalid when the vma manager lock
891
901
* is released.
892
902
*/
893
- mmo = container_of (node , struct i915_mmap_offset , vma_node );
894
- obj = i915_gem_object_get_rcu (mmo -> obj );
903
+ if (!node -> driver_private ) {
904
+ mmo = container_of (node , struct i915_mmap_offset , vma_node );
905
+ obj = i915_gem_object_get_rcu (mmo -> obj );
906
+
907
+ GEM_BUG_ON (obj && obj -> ops -> mmap_ops );
908
+ } else {
909
+ obj = i915_gem_object_get_rcu
910
+ (container_of (node , struct drm_i915_gem_object ,
911
+ base .vma_node ));
912
+
913
+ GEM_BUG_ON (obj && !obj -> ops -> mmap_ops );
914
+ }
895
915
}
896
916
drm_vma_offset_unlock_lookup (dev -> vma_offset_manager );
897
917
rcu_read_unlock ();
@@ -913,7 +933,9 @@ int i915_gem_mmap(struct file *filp, struct vm_area_struct *vma)
913
933
}
914
934
915
935
vma -> vm_flags |= VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP ;
916
- vma -> vm_private_data = mmo ;
936
+
937
+ if (i915_gem_object_has_iomem (obj ))
938
+ vma -> vm_flags |= VM_IO ;
917
939
918
940
/*
919
941
* We keep the ref on mmo->obj, not vm_file, but we require
@@ -927,6 +949,15 @@ int i915_gem_mmap(struct file *filp, struct vm_area_struct *vma)
927
949
/* Drop the initial creation reference, the vma is now holding one. */
928
950
fput (anon );
929
951
952
+ if (obj -> ops -> mmap_ops ) {
953
+ vma -> vm_page_prot = pgprot_decrypted (vm_get_page_prot (vma -> vm_flags ));
954
+ vma -> vm_ops = obj -> ops -> mmap_ops ;
955
+ vma -> vm_private_data = node -> driver_private ;
956
+ return 0 ;
957
+ }
958
+
959
+ vma -> vm_private_data = mmo ;
960
+
930
961
switch (mmo -> mmap_type ) {
931
962
case I915_MMAP_TYPE_WC :
932
963
vma -> vm_page_prot =
0 commit comments