diff options
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index a7f9aaa47c49..e16d57efe39f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | |||
@@ -191,6 +191,26 @@ static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev, | |||
191 | } | 191 | } |
192 | 192 | ||
193 | /** | 193 | /** |
194 | * amdgpu_vm_entries_mask - the mask to get the entry number of a PD/PT | ||
195 | * | ||
196 | * @adev: amdgpu_device pointer | ||
197 | * @level: VMPT level | ||
198 | * | ||
199 | * Returns: | ||
200 | * The mask to extract the entry number of a PD/PT from an address. | ||
201 | */ | ||
202 | static uint32_t amdgpu_vm_entries_mask(struct amdgpu_device *adev, | ||
203 | unsigned int level) | ||
204 | { | ||
205 | if (level <= adev->vm_manager.root_level) | ||
206 | return 0xffffffff; | ||
207 | else if (level != AMDGPU_VM_PTB) | ||
208 | return 0x1ff; | ||
209 | else | ||
210 | return AMDGPU_VM_PTE_COUNT(adev) - 1; | ||
211 | } | ||
212 | |||
213 | /** | ||
194 | * amdgpu_vm_bo_size - returns the size of the BOs in bytes | 214 | * amdgpu_vm_bo_size - returns the size of the BOs in bytes |
195 | * | 215 | * |
196 | * @adev: amdgpu_device pointer | 216 | * @adev: amdgpu_device pointer |
@@ -399,17 +419,17 @@ static void amdgpu_vm_pt_start(struct amdgpu_device *adev, | |||
399 | static bool amdgpu_vm_pt_descendant(struct amdgpu_device *adev, | 419 | static bool amdgpu_vm_pt_descendant(struct amdgpu_device *adev, |
400 | struct amdgpu_vm_pt_cursor *cursor) | 420 | struct amdgpu_vm_pt_cursor *cursor) |
401 | { | 421 | { |
402 | unsigned num_entries, shift, idx; | 422 | unsigned mask, shift, idx; |
403 | 423 | ||
404 | if (!cursor->entry->entries) | 424 | if (!cursor->entry->entries) |
405 | return false; | 425 | return false; |
406 | 426 | ||
407 | BUG_ON(!cursor->entry->base.bo); | 427 | BUG_ON(!cursor->entry->base.bo); |
408 | num_entries = amdgpu_vm_num_entries(adev, cursor->level); | 428 | mask = amdgpu_vm_entries_mask(adev, cursor->level); |
409 | shift = amdgpu_vm_level_shift(adev, cursor->level); | 429 | shift = amdgpu_vm_level_shift(adev, cursor->level); |
410 | 430 | ||
411 | ++cursor->level; | 431 | ++cursor->level; |
412 | idx = (cursor->pfn >> shift) % num_entries; | 432 | idx = (cursor->pfn >> shift) & mask; |
413 | cursor->parent = cursor->entry; | 433 | cursor->parent = cursor->entry; |
414 | cursor->entry = &cursor->entry->entries[idx]; | 434 | cursor->entry = &cursor->entry->entries[idx]; |
415 | return true; | 435 | return true; |
@@ -1599,7 +1619,7 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, | |||
1599 | amdgpu_vm_pt_start(adev, params->vm, start, &cursor); | 1619 | amdgpu_vm_pt_start(adev, params->vm, start, &cursor); |
1600 | while (cursor.pfn < end) { | 1620 | while (cursor.pfn < end) { |
1601 | struct amdgpu_bo *pt = cursor.entry->base.bo; | 1621 | struct amdgpu_bo *pt = cursor.entry->base.bo; |
1602 | unsigned shift, parent_shift, num_entries; | 1622 | unsigned shift, parent_shift, mask; |
1603 | uint64_t incr, entry_end, pe_start; | 1623 | uint64_t incr, entry_end, pe_start; |
1604 | 1624 | ||
1605 | if (!pt) | 1625 | if (!pt) |
@@ -1654,9 +1674,9 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, | |||
1654 | 1674 | ||
1655 | /* Looks good so far, calculate parameters for the update */ | 1675 | /* Looks good so far, calculate parameters for the update */ |
1656 | incr = AMDGPU_GPU_PAGE_SIZE << shift; | 1676 | incr = AMDGPU_GPU_PAGE_SIZE << shift; |
1657 | num_entries = amdgpu_vm_num_entries(adev, cursor.level); | 1677 | mask = amdgpu_vm_entries_mask(adev, cursor.level); |
1658 | pe_start = ((cursor.pfn >> shift) & (num_entries - 1)) * 8; | 1678 | pe_start = ((cursor.pfn >> shift) & mask) * 8; |
1659 | entry_end = num_entries << shift; | 1679 | entry_end = (mask + 1) << shift; |
1660 | entry_end += cursor.pfn & ~(entry_end - 1); | 1680 | entry_end += cursor.pfn & ~(entry_end - 1); |
1661 | entry_end = min(entry_end, end); | 1681 | entry_end = min(entry_end, end); |
1662 | 1682 | ||