@@ -26,7 +26,7 @@ static inline void ivpu_dbg_bo(struct ivpu_device *vdev, struct ivpu_bo *bo, con
2626{
2727 ivpu_dbg (vdev , BO ,
2828 "%6s: bo %8p vpu_addr %9llx size %8zu ctx %d has_pages %d dma_mapped %d mmu_mapped %d wc %d imported %d\n" ,
29- action , bo , bo -> vpu_addr , ivpu_bo_size (bo ), bo -> ctx ? bo -> ctx -> id : 0 ,
29+ action , bo , bo -> vpu_addr , ivpu_bo_size (bo ), bo -> ctx_id ,
3030 (bool )bo -> base .pages , (bool )bo -> base .sgt , bo -> mmu_mapped , bo -> base .map_wc ,
3131 (bool )bo -> base .base .import_attach );
3232}
@@ -92,8 +92,6 @@ ivpu_bo_alloc_vpu_addr(struct ivpu_bo *bo, struct ivpu_mmu_context *ctx,
9292 ivpu_err (vdev , "Failed to add BO to context %u: %d\n" , ctx -> id , ret );
9393 }
9494
95- ivpu_dbg_bo (vdev , bo , "alloc" );
96-
9795 mutex_unlock (& bo -> lock );
9896
9997 drm_dev_exit (idx );
@@ -172,7 +170,7 @@ struct drm_gem_object *ivpu_gem_create_object(struct drm_device *dev, size_t siz
172170 return & bo -> base .base ;
173171}
174172
175- static struct ivpu_bo * ivpu_bo_alloc (struct ivpu_device * vdev , u64 size , u32 flags )
173+ static struct ivpu_bo * ivpu_bo_alloc (struct ivpu_device * vdev , u64 size , u32 flags , u32 ctx_id )
176174{
177175 struct drm_gem_shmem_object * shmem ;
178176 struct ivpu_bo * bo ;
@@ -190,13 +188,16 @@ static struct ivpu_bo *ivpu_bo_alloc(struct ivpu_device *vdev, u64 size, u32 fla
190188 return ERR_CAST (shmem );
191189
192190 bo = to_ivpu_bo (& shmem -> base );
191+ bo -> ctx_id = ctx_id ;
193192 bo -> base .map_wc = flags & DRM_IVPU_BO_WC ;
194193 bo -> flags = flags ;
195194
196195 mutex_lock (& vdev -> bo_list_lock );
197196 list_add_tail (& bo -> bo_list_node , & vdev -> bo_list );
198197 mutex_unlock (& vdev -> bo_list_lock );
199198
199+ ivpu_dbg_bo (vdev , bo , "alloc" );
200+
200201 return bo ;
201202}
202203
@@ -235,8 +236,13 @@ static void ivpu_gem_bo_free(struct drm_gem_object *obj)
235236 mutex_unlock (& vdev -> bo_list_lock );
236237
237238 drm_WARN_ON (& vdev -> drm , !dma_resv_test_signaled (obj -> resv , DMA_RESV_USAGE_READ ));
239+ drm_WARN_ON (& vdev -> drm , ivpu_bo_size (bo ) == 0 );
240+ drm_WARN_ON (& vdev -> drm , bo -> base .vaddr );
238241
239242 ivpu_bo_unbind_locked (bo );
243+ drm_WARN_ON (& vdev -> drm , bo -> mmu_mapped );
244+ drm_WARN_ON (& vdev -> drm , bo -> ctx );
245+
240246 mutex_destroy (& bo -> lock );
241247
242248 drm_WARN_ON (obj -> dev , bo -> base .pages_use_count > 1 );
@@ -271,15 +277,18 @@ int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *fi
271277 if (size == 0 )
272278 return - EINVAL ;
273279
274- bo = ivpu_bo_alloc (vdev , size , args -> flags );
280+ bo = ivpu_bo_alloc (vdev , size , args -> flags , file_priv -> ctx . id );
275281 if (IS_ERR (bo )) {
276282 ivpu_err (vdev , "Failed to allocate BO: %pe (ctx %u size %llu flags 0x%x)" ,
277283 bo , file_priv -> ctx .id , args -> size , args -> flags );
278284 return PTR_ERR (bo );
279285 }
280286
281287 ret = drm_gem_handle_create (file , & bo -> base .base , & args -> handle );
282- if (!ret )
288+ if (ret )
289+ ivpu_err (vdev , "Failed to create handle for BO: %pe (ctx %u size %llu flags 0x%x)" ,
290+ bo , file_priv -> ctx .id , args -> size , args -> flags );
291+ else
283292 args -> vpu_addr = bo -> vpu_addr ;
284293
285294 drm_gem_object_put (& bo -> base .base );
@@ -302,7 +311,7 @@ ivpu_bo_create(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
302311 drm_WARN_ON (& vdev -> drm , !PAGE_ALIGNED (range -> end ));
303312 drm_WARN_ON (& vdev -> drm , !PAGE_ALIGNED (size ));
304313
305- bo = ivpu_bo_alloc (vdev , size , flags );
314+ bo = ivpu_bo_alloc (vdev , size , flags , IVPU_GLOBAL_CONTEXT_MMU_SSID );
306315 if (IS_ERR (bo )) {
307316 ivpu_err (vdev , "Failed to allocate BO: %pe (vpu_addr 0x%llx size %llu flags 0x%x)" ,
308317 bo , range -> start , size , flags );
@@ -406,7 +415,7 @@ static void ivpu_bo_print_info(struct ivpu_bo *bo, struct drm_printer *p)
406415 mutex_lock (& bo -> lock );
407416
408417 drm_printf (p , "%-9p %-3u 0x%-12llx %-10lu 0x%-8x %-4u" ,
409- bo , bo -> ctx ? bo -> ctx -> id : 0 , bo -> vpu_addr , bo -> base .base .size ,
418+ bo , bo -> ctx_id , bo -> vpu_addr , bo -> base .base .size ,
410419 bo -> flags , kref_read (& bo -> base .base .refcount ));
411420
412421 if (bo -> base .pages )
0 commit comments