@@ -38,7 +38,7 @@ struct omap_gem_object {
38
38
/** roll applied when mapping to DMM */
39
39
u32 roll ;
40
40
41
- /** protects dma_addr_cnt , block, pages, dma_addrs and vaddr */
41
+ /** protects pin_cnt , block, pages, dma_addrs and vaddr */
42
42
struct mutex lock ;
43
43
44
44
/**
@@ -50,24 +50,24 @@ struct omap_gem_object {
50
50
* - buffers imported from dmabuf (with the OMAP_BO_MEM_DMABUF flag set)
51
51
* if they are physically contiguous (when sgt->orig_nents == 1)
52
52
*
53
- * - buffers mapped through the TILER when dma_addr_cnt is not zero, in
54
- * which case the DMA address points to the TILER aperture
53
+ * - buffers mapped through the TILER when pin_cnt is not zero, in which
54
+ * case the DMA address points to the TILER aperture
55
55
*
56
56
* Physically contiguous buffers have their DMA address equal to the
57
57
* physical address as we don't remap those buffers through the TILER.
58
58
*
59
59
* Buffers mapped to the TILER have their DMA address pointing to the
60
- * TILER aperture. As TILER mappings are refcounted (through
61
- * dma_addr_cnt) the DMA address must be accessed through omap_gem_pin()
62
- * to ensure that the mapping won't disappear unexpectedly. References
63
- * must be released with omap_gem_unpin().
60
+ * TILER aperture. As TILER mappings are refcounted (through pin_cnt)
61
+ * the DMA address must be accessed through omap_gem_pin() to ensure
62
+ * that the mapping won't disappear unexpectedly. References must be
63
+ * released with omap_gem_unpin().
64
64
*/
65
65
dma_addr_t dma_addr ;
66
66
67
67
/**
68
- * # of users of dma_addr
68
+ * # of users
69
69
*/
70
- refcount_t dma_addr_cnt ;
70
+ refcount_t pin_cnt ;
71
71
72
72
/**
73
73
* If the buffer has been imported from a dmabuf the OMAP_DB_DMABUF flag
@@ -812,32 +812,28 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr)
812
812
813
813
mutex_lock (& omap_obj -> lock );
814
814
815
- if (!omap_gem_is_contiguous (omap_obj ) && priv -> has_dmm ) {
816
- if (refcount_read (& omap_obj -> dma_addr_cnt ) == 0 ) {
815
+ if (!omap_gem_is_contiguous (omap_obj )) {
816
+ if (refcount_read (& omap_obj -> pin_cnt ) == 0 ) {
817
817
818
- refcount_set (& omap_obj -> dma_addr_cnt , 1 );
818
+ refcount_set (& omap_obj -> pin_cnt , 1 );
819
819
820
820
ret = omap_gem_attach_pages (obj );
821
821
if (ret )
822
822
goto fail ;
823
823
824
- ret = omap_gem_pin_tiler (obj );
825
- if (ret )
826
- goto fail ;
824
+ if (priv -> has_dmm ) {
825
+ ret = omap_gem_pin_tiler (obj );
826
+ if (ret )
827
+ goto fail ;
828
+ }
827
829
} else {
828
- refcount_inc (& omap_obj -> dma_addr_cnt );
830
+ refcount_inc (& omap_obj -> pin_cnt );
829
831
}
830
-
831
- if (dma_addr )
832
- * dma_addr = omap_obj -> dma_addr ;
833
- } else if (omap_gem_is_contiguous (omap_obj )) {
834
- if (dma_addr )
835
- * dma_addr = omap_obj -> dma_addr ;
836
- } else {
837
- ret = - EINVAL ;
838
- goto fail ;
839
832
}
840
833
834
+ if (dma_addr )
835
+ * dma_addr = omap_obj -> dma_addr ;
836
+
841
837
fail :
842
838
mutex_unlock (& omap_obj -> lock );
843
839
@@ -856,27 +852,29 @@ static void omap_gem_unpin_locked(struct drm_gem_object *obj)
856
852
struct omap_gem_object * omap_obj = to_omap_bo (obj );
857
853
int ret ;
858
854
859
- if (omap_gem_is_contiguous (omap_obj ) || ! priv -> has_dmm )
855
+ if (omap_gem_is_contiguous (omap_obj ))
860
856
return ;
861
857
862
- if (refcount_dec_and_test (& omap_obj -> dma_addr_cnt )) {
858
+ if (refcount_dec_and_test (& omap_obj -> pin_cnt )) {
863
859
if (omap_obj -> sgt ) {
864
860
sg_free_table (omap_obj -> sgt );
865
861
kfree (omap_obj -> sgt );
866
862
omap_obj -> sgt = NULL ;
867
863
}
868
- ret = tiler_unpin (omap_obj -> block );
869
- if (ret ) {
870
- dev_err (obj -> dev -> dev ,
871
- "could not unpin pages: %d\n" , ret );
872
- }
873
- ret = tiler_release (omap_obj -> block );
874
- if (ret ) {
875
- dev_err (obj -> dev -> dev ,
876
- "could not release unmap: %d\n" , ret );
864
+ if (priv -> has_dmm ) {
865
+ ret = tiler_unpin (omap_obj -> block );
866
+ if (ret ) {
867
+ dev_err (obj -> dev -> dev ,
868
+ "could not unpin pages: %d\n" , ret );
869
+ }
870
+ ret = tiler_release (omap_obj -> block );
871
+ if (ret ) {
872
+ dev_err (obj -> dev -> dev ,
873
+ "could not release unmap: %d\n" , ret );
874
+ }
875
+ omap_obj -> dma_addr = 0 ;
876
+ omap_obj -> block = NULL ;
877
877
}
878
- omap_obj -> dma_addr = 0 ;
879
- omap_obj -> block = NULL ;
880
878
}
881
879
}
882
880
@@ -909,7 +907,7 @@ int omap_gem_rotated_dma_addr(struct drm_gem_object *obj, u32 orient,
909
907
910
908
mutex_lock (& omap_obj -> lock );
911
909
912
- if ((refcount_read (& omap_obj -> dma_addr_cnt ) > 0 ) && omap_obj -> block &&
910
+ if ((refcount_read (& omap_obj -> pin_cnt ) > 0 ) && omap_obj -> block &&
913
911
(omap_obj -> flags & OMAP_BO_TILED_MASK )) {
914
912
* dma_addr = tiler_tsptr (omap_obj -> block , orient , x , y );
915
913
ret = 0 ;
@@ -977,7 +975,8 @@ int omap_gem_put_pages(struct drm_gem_object *obj)
977
975
return 0 ;
978
976
}
979
977
980
- struct sg_table * omap_gem_get_sg (struct drm_gem_object * obj )
978
+ struct sg_table * omap_gem_get_sg (struct drm_gem_object * obj ,
979
+ enum dma_data_direction dir )
981
980
{
982
981
struct omap_gem_object * omap_obj = to_omap_bo (obj );
983
982
dma_addr_t addr ;
@@ -1002,28 +1001,44 @@ struct sg_table *omap_gem_get_sg(struct drm_gem_object *obj)
1002
1001
goto err_unpin ;
1003
1002
}
1004
1003
1005
- if (omap_obj -> flags & OMAP_BO_TILED_MASK ) {
1006
- enum tiler_fmt fmt = gem2fmt (omap_obj -> flags );
1004
+ if (addr ) {
1005
+ if (omap_obj -> flags & OMAP_BO_TILED_MASK ) {
1006
+ enum tiler_fmt fmt = gem2fmt (omap_obj -> flags );
1007
1007
1008
- len = omap_obj -> width << (int )fmt ;
1009
- count = omap_obj -> height ;
1010
- stride = tiler_stride (fmt , 0 );
1008
+ len = omap_obj -> width << (int )fmt ;
1009
+ count = omap_obj -> height ;
1010
+ stride = tiler_stride (fmt , 0 );
1011
+ } else {
1012
+ len = obj -> size ;
1013
+ count = 1 ;
1014
+ stride = 0 ;
1015
+ }
1011
1016
} else {
1012
- len = obj -> size ;
1013
- count = 1 ;
1014
- stride = 0 ;
1017
+ count = obj -> size >> PAGE_SHIFT ;
1015
1018
}
1016
1019
1017
1020
ret = sg_alloc_table (sgt , count , GFP_KERNEL );
1018
1021
if (ret )
1019
1022
goto err_free ;
1020
1023
1021
- for_each_sg (sgt -> sgl , sg , count , i ) {
1022
- sg_set_page (sg , phys_to_page (addr ), len , offset_in_page (addr ));
1023
- sg_dma_address (sg ) = addr ;
1024
- sg_dma_len (sg ) = len ;
1024
+ /* this must be after omap_gem_pin() to ensure we have pages attached */
1025
+ omap_gem_dma_sync_buffer (obj , dir );
1026
+
1027
+ if (addr ) {
1028
+ for_each_sg (sgt -> sgl , sg , count , i ) {
1029
+ sg_set_page (sg , phys_to_page (addr ), len ,
1030
+ offset_in_page (addr ));
1031
+ sg_dma_address (sg ) = addr ;
1032
+ sg_dma_len (sg ) = len ;
1025
1033
1026
- addr += stride ;
1034
+ addr += stride ;
1035
+ }
1036
+ } else {
1037
+ for_each_sg (sgt -> sgl , sg , count , i ) {
1038
+ sg_set_page (sg , omap_obj -> pages [i ], PAGE_SIZE , 0 );
1039
+ sg_dma_address (sg ) = omap_obj -> dma_addrs [i ];
1040
+ sg_dma_len (sg ) = PAGE_SIZE ;
1041
+ }
1027
1042
}
1028
1043
1029
1044
omap_obj -> sgt = sgt ;
@@ -1133,7 +1148,7 @@ void omap_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
1133
1148
seq_printf (m , "%08x: %2d (%2d) %08llx %pad (%2d) %p %4d" ,
1134
1149
omap_obj -> flags , obj -> name , kref_read (& obj -> refcount ),
1135
1150
off , & omap_obj -> dma_addr ,
1136
- refcount_read (& omap_obj -> dma_addr_cnt ),
1151
+ refcount_read (& omap_obj -> pin_cnt ),
1137
1152
omap_obj -> vaddr , omap_obj -> roll );
1138
1153
1139
1154
if (omap_obj -> flags & OMAP_BO_TILED_MASK ) {
@@ -1196,7 +1211,7 @@ static void omap_gem_free_object(struct drm_gem_object *obj)
1196
1211
mutex_lock (& omap_obj -> lock );
1197
1212
1198
1213
/* The object should not be pinned. */
1199
- WARN_ON (refcount_read (& omap_obj -> dma_addr_cnt ) > 0 );
1214
+ WARN_ON (refcount_read (& omap_obj -> pin_cnt ) > 0 );
1200
1215
1201
1216
if (omap_obj -> pages ) {
1202
1217
if (omap_obj -> flags & OMAP_BO_MEM_DMABUF )
0 commit comments