@@ -2390,6 +2390,8 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,
23902390 * @offset: requested offset in the BO
23912391 * @size: BO size in bytes
23922392 * @flags: attributes of pages (read/write/valid/etc.)
2393+ * @updated_bo_va: will be set to the (up to 2) bo_va's that have new shrunk
2394+ * mappings, or unchanged otherwise.
23932395 *
23942396 * Add a mapping of the BO at the specefied addr into the VM. Replace existing
23952397 * mappings as we do so.
@@ -2402,7 +2404,8 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,
24022404int amdgpu_vm_bo_replace_map (struct amdgpu_device * adev ,
24032405 struct amdgpu_bo_va * bo_va ,
24042406 uint64_t saddr , uint64_t offset ,
2405- uint64_t size , uint64_t flags )
2407+ uint64_t size , uint64_t flags ,
2408+ struct amdgpu_bo_va * * updated_bo_va )
24062409{
24072410 struct amdgpu_bo_va_mapping * mapping ;
24082411 struct amdgpu_bo * bo = bo_va -> base .bo ;
@@ -2426,7 +2429,8 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev,
24262429 if (!mapping )
24272430 return - ENOMEM ;
24282431
2429- r = amdgpu_vm_bo_clear_mappings (adev , bo_va -> base .vm , saddr , size );
2432+ r = amdgpu_vm_bo_clear_mappings (adev , bo_va -> base .vm , saddr , size ,
2433+ updated_bo_va );
24302434 if (r ) {
24312435 kfree (mapping );
24322436 return r ;
@@ -2499,13 +2503,53 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
24992503 return 0 ;
25002504}
25012505
2506+ /**
2507+ * amdgpu_vm_bo_clear_mappings_bo_va - determine bo_va of split mappings.
2508+ *
2509+ * @adev: amdgpu_device pointer
2510+ * @vm: VM structure to use
2511+ * @saddr: start of the range
2512+ * @size: size of the range
2513+ * @updated_bo_va: will be set to the (up to 2) bo_va's that have new shrunk
2514+ * mappings, or unchanged otherwise.
2515+ *
2516+ * Determines the bo_va of the split mappings that would result from
2517+ * amdgpu_vm_bo_clear_mappings.
2518+ */
2519+ void amdgpu_vm_bo_clear_mappings_bo_va (struct amdgpu_device * adev ,
2520+ struct amdgpu_vm * vm ,
2521+ uint64_t saddr , uint64_t size ,
2522+ struct amdgpu_bo_va * * updated_bo_va )
2523+ {
2524+ struct amdgpu_bo_va_mapping * tmp ;
2525+ uint64_t eaddr ;
2526+
2527+ eaddr = saddr + size - 1 ;
2528+ saddr /= AMDGPU_GPU_PAGE_SIZE ;
2529+ eaddr /= AMDGPU_GPU_PAGE_SIZE ;
2530+
2531+ /* Now gather all removed mappings */
2532+ tmp = amdgpu_vm_it_iter_first (& vm -> va , saddr , eaddr );
2533+ while (tmp ) {
2534+ if (tmp -> start < saddr )
2535+ * updated_bo_va ++ = tmp -> bo_va ;
2536+
2537+ if (tmp -> last > eaddr )
2538+ * updated_bo_va ++ = tmp -> bo_va ;
2539+
2540+ tmp = amdgpu_vm_it_iter_next (tmp , saddr , eaddr );
2541+ }
2542+ }
2543+
25022544/**
25032545 * amdgpu_vm_bo_clear_mappings - remove all mappings in a specific range
25042546 *
25052547 * @adev: amdgpu_device pointer
25062548 * @vm: VM structure to use
25072549 * @saddr: start of the range
25082550 * @size: size of the range
2551+ * @updated_bo_va: will be set to the (up to 2) bo_va's that have new shrunk
2552+ * mappings, or unchanged otherwise.
25092553 *
25102554 * Remove all mappings in a range, split them as appropriate.
25112555 *
@@ -2514,7 +2558,8 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
25142558 */
25152559int amdgpu_vm_bo_clear_mappings (struct amdgpu_device * adev ,
25162560 struct amdgpu_vm * vm ,
2517- uint64_t saddr , uint64_t size )
2561+ uint64_t saddr , uint64_t size ,
2562+ struct amdgpu_bo_va * * updated_bo_va )
25182563{
25192564 struct amdgpu_bo_va_mapping * before , * after , * tmp , * next ;
25202565 LIST_HEAD (removed );
@@ -2584,6 +2629,7 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
25842629
25852630 /* Insert partial mapping before the range */
25862631 if (!list_empty (& before -> list )) {
2632+ * updated_bo_va ++ = before -> bo_va ;
25872633 amdgpu_vm_it_insert (before , & vm -> va );
25882634 if (before -> flags & AMDGPU_PTE_PRT )
25892635 amdgpu_vm_prt_get (adev );
@@ -2593,6 +2639,7 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
25932639
25942640 /* Insert partial mapping after the range */
25952641 if (!list_empty (& after -> list )) {
2642+ * updated_bo_va ++ = after -> bo_va ;
25962643 amdgpu_vm_it_insert (after , & vm -> va );
25972644 if (after -> flags & AMDGPU_PTE_PRT )
25982645 amdgpu_vm_prt_get (adev );
0 commit comments