1616#include "msm_gpu.h"
1717#include "msm_gem.h"
1818#include "msm_gpu_trace.h"
19+ #include "msm_syncobj.h"
1920
2021/* For userspace errors, use DRM_UT_DRIVER.. so that userspace can enable
2122 * error msgs for debugging, but we don't spam dmesg by default
@@ -491,173 +492,6 @@ void msm_submit_retire(struct msm_gem_submit *submit)
491492 }
492493}
493494
494- struct msm_submit_post_dep {
495- struct drm_syncobj * syncobj ;
496- uint64_t point ;
497- struct dma_fence_chain * chain ;
498- };
499-
500- static struct drm_syncobj * * msm_parse_deps (struct msm_gem_submit * submit ,
501- struct drm_file * file ,
502- uint64_t in_syncobjs_addr ,
503- uint32_t nr_in_syncobjs ,
504- size_t syncobj_stride )
505- {
506- struct drm_syncobj * * syncobjs = NULL ;
507- struct drm_msm_gem_submit_syncobj syncobj_desc = {0 };
508- int ret = 0 ;
509- uint32_t i , j ;
510-
511- syncobjs = kcalloc (nr_in_syncobjs , sizeof (* syncobjs ),
512- GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY );
513- if (!syncobjs )
514- return ERR_PTR (- ENOMEM );
515-
516- for (i = 0 ; i < nr_in_syncobjs ; ++ i ) {
517- uint64_t address = in_syncobjs_addr + i * syncobj_stride ;
518-
519- if (copy_from_user (& syncobj_desc ,
520- u64_to_user_ptr (address ),
521- min (syncobj_stride , sizeof (syncobj_desc )))) {
522- ret = - EFAULT ;
523- break ;
524- }
525-
526- if (syncobj_desc .point &&
527- !drm_core_check_feature (submit -> dev , DRIVER_SYNCOBJ_TIMELINE )) {
528- ret = SUBMIT_ERROR (EOPNOTSUPP , submit , "syncobj timeline unsupported" );
529- break ;
530- }
531-
532- if (syncobj_desc .flags & ~MSM_SUBMIT_SYNCOBJ_FLAGS ) {
533- ret = SUBMIT_ERROR (EINVAL , submit , "invalid syncobj flags: %x" , syncobj_desc .flags );
534- break ;
535- }
536-
537- ret = drm_sched_job_add_syncobj_dependency (& submit -> base , file ,
538- syncobj_desc .handle , syncobj_desc .point );
539- if (ret )
540- break ;
541-
542- if (syncobj_desc .flags & MSM_SUBMIT_SYNCOBJ_RESET ) {
543- syncobjs [i ] =
544- drm_syncobj_find (file , syncobj_desc .handle );
545- if (!syncobjs [i ]) {
546- ret = SUBMIT_ERROR (EINVAL , submit , "invalid syncobj handle: %u" , i );
547- break ;
548- }
549- }
550- }
551-
552- if (ret ) {
553- for (j = 0 ; j <= i ; ++ j ) {
554- if (syncobjs [j ])
555- drm_syncobj_put (syncobjs [j ]);
556- }
557- kfree (syncobjs );
558- return ERR_PTR (ret );
559- }
560- return syncobjs ;
561- }
562-
563- static void msm_reset_syncobjs (struct drm_syncobj * * syncobjs ,
564- uint32_t nr_syncobjs )
565- {
566- uint32_t i ;
567-
568- for (i = 0 ; syncobjs && i < nr_syncobjs ; ++ i ) {
569- if (syncobjs [i ])
570- drm_syncobj_replace_fence (syncobjs [i ], NULL );
571- }
572- }
573-
574- static struct msm_submit_post_dep * msm_parse_post_deps (struct drm_device * dev ,
575- struct drm_file * file ,
576- uint64_t syncobjs_addr ,
577- uint32_t nr_syncobjs ,
578- size_t syncobj_stride )
579- {
580- struct msm_submit_post_dep * post_deps ;
581- struct drm_msm_gem_submit_syncobj syncobj_desc = {0 };
582- int ret = 0 ;
583- uint32_t i , j ;
584-
585- post_deps = kcalloc (nr_syncobjs , sizeof (* post_deps ),
586- GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY );
587- if (!post_deps )
588- return ERR_PTR (- ENOMEM );
589-
590- for (i = 0 ; i < nr_syncobjs ; ++ i ) {
591- uint64_t address = syncobjs_addr + i * syncobj_stride ;
592-
593- if (copy_from_user (& syncobj_desc ,
594- u64_to_user_ptr (address ),
595- min (syncobj_stride , sizeof (syncobj_desc )))) {
596- ret = - EFAULT ;
597- break ;
598- }
599-
600- post_deps [i ].point = syncobj_desc .point ;
601-
602- if (syncobj_desc .flags ) {
603- ret = UERR (EINVAL , dev , "invalid syncobj flags" );
604- break ;
605- }
606-
607- if (syncobj_desc .point ) {
608- if (!drm_core_check_feature (dev ,
609- DRIVER_SYNCOBJ_TIMELINE )) {
610- ret = UERR (EOPNOTSUPP , dev , "syncobj timeline unsupported" );
611- break ;
612- }
613-
614- post_deps [i ].chain = dma_fence_chain_alloc ();
615- if (!post_deps [i ].chain ) {
616- ret = - ENOMEM ;
617- break ;
618- }
619- }
620-
621- post_deps [i ].syncobj =
622- drm_syncobj_find (file , syncobj_desc .handle );
623- if (!post_deps [i ].syncobj ) {
624- ret = UERR (EINVAL , dev , "invalid syncobj handle" );
625- break ;
626- }
627- }
628-
629- if (ret ) {
630- for (j = 0 ; j <= i ; ++ j ) {
631- dma_fence_chain_free (post_deps [j ].chain );
632- if (post_deps [j ].syncobj )
633- drm_syncobj_put (post_deps [j ].syncobj );
634- }
635-
636- kfree (post_deps );
637- return ERR_PTR (ret );
638- }
639-
640- return post_deps ;
641- }
642-
643- static void msm_process_post_deps (struct msm_submit_post_dep * post_deps ,
644- uint32_t count , struct dma_fence * fence )
645- {
646- uint32_t i ;
647-
648- for (i = 0 ; post_deps && i < count ; ++ i ) {
649- if (post_deps [i ].chain ) {
650- drm_syncobj_add_point (post_deps [i ].syncobj ,
651- post_deps [i ].chain ,
652- fence , post_deps [i ].point );
653- post_deps [i ].chain = NULL ;
654- } else {
655- drm_syncobj_replace_fence (post_deps [i ].syncobj ,
656- fence );
657- }
658- }
659- }
660-
661495int msm_ioctl_gem_submit (struct drm_device * dev , void * data ,
662496 struct drm_file * file )
663497{
@@ -668,7 +502,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
668502 struct msm_gpu * gpu = priv -> gpu ;
669503 struct msm_gpu_submitqueue * queue ;
670504 struct msm_ringbuffer * ring ;
671- struct msm_submit_post_dep * post_deps = NULL ;
505+ struct msm_syncobj_post_dep * post_deps = NULL ;
672506 struct drm_syncobj * * syncobjs_to_reset = NULL ;
673507 struct sync_file * sync_file = NULL ;
674508 int out_fence_fd = -1 ;
@@ -746,21 +580,21 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
746580 }
747581
748582 if (args -> flags & MSM_SUBMIT_SYNCOBJ_IN ) {
749- syncobjs_to_reset = msm_parse_deps ( submit , file ,
750- args -> in_syncobjs ,
751- args -> nr_in_syncobjs ,
752- args -> syncobj_stride );
583+ syncobjs_to_reset = msm_syncobj_parse_deps ( dev , & submit -> base ,
584+ file , args -> in_syncobjs ,
585+ args -> nr_in_syncobjs ,
586+ args -> syncobj_stride );
753587 if (IS_ERR (syncobjs_to_reset )) {
754588 ret = PTR_ERR (syncobjs_to_reset );
755589 goto out_unlock ;
756590 }
757591 }
758592
759593 if (args -> flags & MSM_SUBMIT_SYNCOBJ_OUT ) {
760- post_deps = msm_parse_post_deps (dev , file ,
761- args -> out_syncobjs ,
762- args -> nr_out_syncobjs ,
763- args -> syncobj_stride );
594+ post_deps = msm_syncobj_parse_post_deps (dev , file ,
595+ args -> out_syncobjs ,
596+ args -> nr_out_syncobjs ,
597+ args -> syncobj_stride );
764598 if (IS_ERR (post_deps )) {
765599 ret = PTR_ERR (post_deps );
766600 goto out_unlock ;
@@ -903,10 +737,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
903737 args -> fence = submit -> fence_id ;
904738 queue -> last_fence = submit -> fence_id ;
905739
906- msm_reset_syncobjs (syncobjs_to_reset , args -> nr_in_syncobjs );
907- msm_process_post_deps (post_deps , args -> nr_out_syncobjs ,
908- submit -> user_fence );
909-
740+ msm_syncobj_reset (syncobjs_to_reset , args -> nr_in_syncobjs );
741+ msm_syncobj_process_post_deps (post_deps , args -> nr_out_syncobjs , submit -> user_fence );
910742
911743out :
912744 submit_cleanup (submit , !!ret );
0 commit comments