Commit cb90b97b authored by Christian König's avatar Christian König Committed by Alex Deucher

drm/amdgpu: add amdgpu_vm_entries_mask v2

We can't get the mask for the root directory from the number of entries.

So add a new function to avoid that problem.

v2: fix typo in mask
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarHuang Rui <ray.huang@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 5232da2f
...@@ -190,6 +190,26 @@ static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev, ...@@ -190,6 +190,26 @@ static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
return AMDGPU_VM_PTE_COUNT(adev); return AMDGPU_VM_PTE_COUNT(adev);
} }
/**
* amdgpu_vm_entries_mask - the mask to get the entry number of a PD/PT
*
* @adev: amdgpu_device pointer
* @level: VMPT level
*
* Returns:
* The mask to extract the entry number of a PD/PT from an address.
*/
static uint32_t amdgpu_vm_entries_mask(struct amdgpu_device *adev,
unsigned int level)
{
if (level <= adev->vm_manager.root_level)
return 0xffffffff;
else if (level != AMDGPU_VM_PTB)
return 0x1ff;
else
return AMDGPU_VM_PTE_COUNT(adev) - 1;
}
/** /**
* amdgpu_vm_bo_size - returns the size of the BOs in bytes * amdgpu_vm_bo_size - returns the size of the BOs in bytes
* *
...@@ -399,17 +419,17 @@ static void amdgpu_vm_pt_start(struct amdgpu_device *adev, ...@@ -399,17 +419,17 @@ static void amdgpu_vm_pt_start(struct amdgpu_device *adev,
static bool amdgpu_vm_pt_descendant(struct amdgpu_device *adev, static bool amdgpu_vm_pt_descendant(struct amdgpu_device *adev,
struct amdgpu_vm_pt_cursor *cursor) struct amdgpu_vm_pt_cursor *cursor)
{ {
unsigned num_entries, shift, idx; unsigned mask, shift, idx;
if (!cursor->entry->entries) if (!cursor->entry->entries)
return false; return false;
BUG_ON(!cursor->entry->base.bo); BUG_ON(!cursor->entry->base.bo);
num_entries = amdgpu_vm_num_entries(adev, cursor->level); mask = amdgpu_vm_entries_mask(adev, cursor->level);
shift = amdgpu_vm_level_shift(adev, cursor->level); shift = amdgpu_vm_level_shift(adev, cursor->level);
++cursor->level; ++cursor->level;
idx = (cursor->pfn >> shift) % num_entries; idx = (cursor->pfn >> shift) & mask;
cursor->parent = cursor->entry; cursor->parent = cursor->entry;
cursor->entry = &cursor->entry->entries[idx]; cursor->entry = &cursor->entry->entries[idx];
return true; return true;
...@@ -1599,7 +1619,7 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, ...@@ -1599,7 +1619,7 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
amdgpu_vm_pt_start(adev, params->vm, start, &cursor); amdgpu_vm_pt_start(adev, params->vm, start, &cursor);
while (cursor.pfn < end) { while (cursor.pfn < end) {
struct amdgpu_bo *pt = cursor.entry->base.bo; struct amdgpu_bo *pt = cursor.entry->base.bo;
unsigned shift, parent_shift, num_entries; unsigned shift, parent_shift, mask;
uint64_t incr, entry_end, pe_start; uint64_t incr, entry_end, pe_start;
if (!pt) if (!pt)
...@@ -1654,9 +1674,9 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, ...@@ -1654,9 +1674,9 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
/* Looks good so far, calculate parameters for the update */ /* Looks good so far, calculate parameters for the update */
incr = AMDGPU_GPU_PAGE_SIZE << shift; incr = AMDGPU_GPU_PAGE_SIZE << shift;
num_entries = amdgpu_vm_num_entries(adev, cursor.level); mask = amdgpu_vm_entries_mask(adev, cursor.level);
pe_start = ((cursor.pfn >> shift) & (num_entries - 1)) * 8; pe_start = ((cursor.pfn >> shift) & mask) * 8;
entry_end = num_entries << shift; entry_end = (mask + 1) << shift;
entry_end += cursor.pfn & ~(entry_end - 1); entry_end += cursor.pfn & ~(entry_end - 1);
entry_end = min(entry_end, end); entry_end = min(entry_end, end);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment