@@ -226,11 +226,10 @@ aie2_sched_resp_handler(void *handle, void __iomem *data, size_t size)
226226}
227227
228228static int
229- aie2_sched_nocmd_resp_handler (void * handle , void __iomem * data , size_t size )
229+ aie2_sched_drvcmd_resp_handler (void * handle , void __iomem * data , size_t size )
230230{
231231 struct amdxdna_sched_job * job = handle ;
232232 int ret = 0 ;
233- u32 status ;
234233
235234 if (unlikely (!data ))
236235 goto out ;
@@ -240,8 +239,7 @@ aie2_sched_nocmd_resp_handler(void *handle, void __iomem *data, size_t size)
240239 goto out ;
241240 }
242241
243- status = readl (data );
244- XDNA_DBG (job -> hwctx -> client -> xdna , "Resp status 0x%x" , status );
242+ job -> drv_cmd -> result = readl (data );
245243
246244out :
247245 aie2_sched_notify (job );
@@ -314,8 +312,18 @@ aie2_sched_job_run(struct drm_sched_job *sched_job)
314312 kref_get (& job -> refcnt );
315313 fence = dma_fence_get (job -> fence );
316314
317- if (unlikely (!cmd_abo )) {
318- ret = aie2_sync_bo (hwctx , job , aie2_sched_nocmd_resp_handler );
315+ if (job -> drv_cmd ) {
316+ switch (job -> drv_cmd -> opcode ) {
317+ case SYNC_DEBUG_BO :
318+ ret = aie2_sync_bo (hwctx , job , aie2_sched_drvcmd_resp_handler );
319+ break ;
320+ case ATTACH_DEBUG_BO :
321+ ret = aie2_config_debug_bo (hwctx , job , aie2_sched_drvcmd_resp_handler );
322+ break ;
323+ default :
324+ ret = - EINVAL ;
325+ break ;
326+ }
319327 goto out ;
320328 }
321329
@@ -766,6 +774,74 @@ static int aie2_hwctx_cu_config(struct amdxdna_hwctx *hwctx, void *buf, u32 size
766774 return ret ;
767775}
768776
777+ static void aie2_cmd_wait (struct amdxdna_hwctx * hwctx , u64 seq )
778+ {
779+ struct dma_fence * out_fence = aie2_cmd_get_out_fence (hwctx , seq );
780+
781+ if (!out_fence ) {
782+ XDNA_ERR (hwctx -> client -> xdna , "Failed to get fence" );
783+ return ;
784+ }
785+
786+ dma_fence_wait_timeout (out_fence , false, MAX_SCHEDULE_TIMEOUT );
787+ dma_fence_put (out_fence );
788+ }
789+
790+ static int aie2_hwctx_cfg_debug_bo (struct amdxdna_hwctx * hwctx , u32 bo_hdl ,
791+ bool attach )
792+ {
793+ struct amdxdna_client * client = hwctx -> client ;
794+ struct amdxdna_dev * xdna = client -> xdna ;
795+ struct amdxdna_drv_cmd cmd = { 0 };
796+ struct amdxdna_gem_obj * abo ;
797+ u64 seq ;
798+ int ret ;
799+
800+ abo = amdxdna_gem_get_obj (client , bo_hdl , AMDXDNA_BO_DEV );
801+ if (!abo ) {
802+ XDNA_ERR (xdna , "Get bo %d failed" , bo_hdl );
803+ return - EINVAL ;
804+ }
805+
806+ if (attach ) {
807+ if (abo -> assigned_hwctx != AMDXDNA_INVALID_CTX_HANDLE ) {
808+ ret = - EBUSY ;
809+ goto put_obj ;
810+ }
811+ cmd .opcode = ATTACH_DEBUG_BO ;
812+ } else {
813+ if (abo -> assigned_hwctx != hwctx -> id ) {
814+ ret = - EINVAL ;
815+ goto put_obj ;
816+ }
817+ cmd .opcode = DETACH_DEBUG_BO ;
818+ }
819+
820+ ret = amdxdna_cmd_submit (client , & cmd , AMDXDNA_INVALID_BO_HANDLE ,
821+ & bo_hdl , 1 , hwctx -> id , & seq );
822+ if (ret ) {
823+ XDNA_ERR (xdna , "Submit command failed" );
824+ goto put_obj ;
825+ }
826+
827+ aie2_cmd_wait (hwctx , seq );
828+ if (cmd .result ) {
829+ XDNA_ERR (xdna , "Response failure 0x%x" , cmd .result );
830+ goto put_obj ;
831+ }
832+
833+ if (attach )
834+ abo -> assigned_hwctx = hwctx -> id ;
835+ else
836+ abo -> assigned_hwctx = AMDXDNA_INVALID_CTX_HANDLE ;
837+
838+ XDNA_DBG (xdna , "Config debug BO %d to %s" , bo_hdl , hwctx -> name );
839+
840+ put_obj :
841+ amdxdna_gem_put_obj (abo );
842+ return ret ;
843+ }
844+
769845int aie2_hwctx_config (struct amdxdna_hwctx * hwctx , u32 type , u64 value , void * buf , u32 size )
770846{
771847 struct amdxdna_dev * xdna = hwctx -> client -> xdna ;
@@ -775,14 +851,40 @@ int aie2_hwctx_config(struct amdxdna_hwctx *hwctx, u32 type, u64 value, void *bu
775851 case DRM_AMDXDNA_HWCTX_CONFIG_CU :
776852 return aie2_hwctx_cu_config (hwctx , buf , size );
777853 case DRM_AMDXDNA_HWCTX_ASSIGN_DBG_BUF :
854+ return aie2_hwctx_cfg_debug_bo (hwctx , (u32 )value , true);
778855 case DRM_AMDXDNA_HWCTX_REMOVE_DBG_BUF :
779- return - EOPNOTSUPP ;
856+ return aie2_hwctx_cfg_debug_bo ( hwctx , ( u32 ) value , false) ;
780857 default :
781858 XDNA_DBG (xdna , "Not supported type %d" , type );
782859 return - EOPNOTSUPP ;
783860 }
784861}
785862
863+ int aie2_hwctx_sync_debug_bo (struct amdxdna_hwctx * hwctx , u32 debug_bo_hdl )
864+ {
865+ struct amdxdna_client * client = hwctx -> client ;
866+ struct amdxdna_dev * xdna = client -> xdna ;
867+ struct amdxdna_drv_cmd cmd = { 0 };
868+ u64 seq ;
869+ int ret ;
870+
871+ cmd .opcode = SYNC_DEBUG_BO ;
872+ ret = amdxdna_cmd_submit (client , & cmd , AMDXDNA_INVALID_BO_HANDLE ,
873+ & debug_bo_hdl , 1 , hwctx -> id , & seq );
874+ if (ret ) {
875+ XDNA_ERR (xdna , "Submit command failed" );
876+ return ret ;
877+ }
878+
879+ aie2_cmd_wait (hwctx , seq );
880+ if (cmd .result ) {
881+ XDNA_ERR (xdna , "Response failure 0x%x" , cmd .result );
882+ return ret ;
883+ }
884+
885+ return 0 ;
886+ }
887+
786888static int aie2_populate_range (struct amdxdna_gem_obj * abo )
787889{
788890 struct amdxdna_dev * xdna = to_xdna_dev (to_gobj (abo )-> dev );
0 commit comments