@@ -417,9 +417,6 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
417417 /* always clear VRAM */
418418 flags |= AMDGPU_GEM_CREATE_VRAM_CLEARED ;
419419
420- if (args -> in .domains & AMDGPU_GEM_DOMAIN_MMIO_REMAP )
421- return - EINVAL ;
422-
423420 /* create a gem object to contain this object in */
424421 if (args -> in .domains & (AMDGPU_GEM_DOMAIN_GDS |
425422 AMDGPU_GEM_DOMAIN_GWS | AMDGPU_GEM_DOMAIN_OA )) {
@@ -732,15 +729,23 @@ amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
732729 struct amdgpu_bo_va * bo_va ,
733730 uint32_t operation )
734731{
735- struct dma_fence * clear_fence = dma_fence_get_stub ();
736- struct dma_fence * last_update = NULL ;
737- int r ;
732+ struct dma_fence * fence ;
733+ int r = 0 ;
734+
735+ /* Always start from the VM's existing last update fence. */
736+ fence = dma_fence_get (vm -> last_update );
738737
739738 if (!amdgpu_vm_ready (vm ))
740- return clear_fence ;
739+ return fence ;
741740
742- /* First clear freed BOs and get a fence for that work, if any. */
743- r = amdgpu_vm_clear_freed (adev , vm , & clear_fence );
741+ /*
742+ * First clean up any freed mappings in the VM.
743+ *
744+ * amdgpu_vm_clear_freed() may replace @fence with a new fence if it
745+ * schedules GPU work. If nothing needs clearing, @fence can remain as
746+ * the original vm->last_update.
747+ */
748+ r = amdgpu_vm_clear_freed (adev , vm , & fence );
744749 if (r )
745750 goto error ;
746751
@@ -758,53 +763,46 @@ amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
758763 goto error ;
759764
760765 /*
761- * Decide which fence represents the "last update" for this VM/BO:
766+ * Decide which fence best represents the last update:
767+ *
768+ * MAP/REPLACE:
769+ * - For always-valid mappings, use vm->last_update.
770+ * - Otherwise, export bo_va->last_pt_update.
762771 *
763- * - For MAP/REPLACE we want the PT update fence, which is tracked as
764- * either vm->last_update (for always-valid BOs) or bo_va->last_pt_update
765- * (for per-BO updates) .
772+ * UNMAP/CLEAR:
773+ * Keep the fence returned by amdgpu_vm_clear_freed(). If no work was
774+ * needed, it can remain as vm->last_pt_update .
766775 *
767- * - For UNMAP/CLEAR we rely on the fence returned by
768- * amdgpu_vm_clear_freed(), which already covers the page table work
769- * for the removed mappings .
776+ * The VM and BO update fences are always initialized to a valid value.
777+ * vm->last_update and bo_va->last_pt_update always start as valid fences.
778+ * and are never expected to be NULL .
770779 */
771780 switch (operation ) {
772781 case AMDGPU_VA_OP_MAP :
773782 case AMDGPU_VA_OP_REPLACE :
774- if (bo_va && bo_va -> base .bo ) {
775- if (amdgpu_vm_is_bo_always_valid (vm , bo_va -> base .bo )) {
776- if (vm -> last_update )
777- last_update = dma_fence_get (vm -> last_update );
778- } else {
779- if (bo_va -> last_pt_update )
780- last_update = dma_fence_get (bo_va -> last_pt_update );
781- }
782- }
783+ /*
784+ * For MAP/REPLACE, return the page table update fence for the
785+ * mapping we just modified. bo_va is expected to be valid here.
786+ */
787+ dma_fence_put (fence );
788+
789+ if (amdgpu_vm_is_bo_always_valid (vm , bo_va -> base .bo ))
790+ fence = dma_fence_get (vm -> last_update );
791+ else
792+ fence = dma_fence_get (bo_va -> last_pt_update );
783793 break ;
784794 case AMDGPU_VA_OP_UNMAP :
785795 case AMDGPU_VA_OP_CLEAR :
786- if (clear_fence )
787- last_update = dma_fence_get (clear_fence );
788- break ;
789796 default :
797+ /* keep @fence as returned by amdgpu_vm_clear_freed() */
790798 break ;
791799 }
792800
793801error :
794802 if (r && r != - ERESTARTSYS )
795803 DRM_ERROR ("Couldn't update BO_VA (%d)\n" , r );
796804
797- /*
798- * If we managed to pick a more specific last-update fence, prefer it
799- * over the generic clear_fence and drop the extra reference to the
800- * latter.
801- */
802- if (last_update ) {
803- dma_fence_put (clear_fence );
804- return last_update ;
805- }
806-
807- return clear_fence ;
805+ return fence ;
808806}
809807
810808int amdgpu_gem_va_ioctl (struct drm_device * dev , void * data ,
0 commit comments