提交 50261151 编写于 作者: N Nils Wallménius 提交者: Alex Deucher

drm/amdgpu: simplify allocation of scratch regs

The scratch regs are sequential so there's no need to keep
them in an array, we can just return the index of the first
free register + the base register. Also change the array
of bools for keeping track of the free regs to a bitfield.
Reviewed-by: NChristian König <christian.koenig@amd.com>
Signed-off-by: NNils Wallménius <nils.wallmenius@gmail.com>
Signed-off-by: NAlex Deucher <alexander.deucher@amd.com>
上级 cb341a31
...@@ -794,8 +794,7 @@ struct amdgpu_kiq { ...@@ -794,8 +794,7 @@ struct amdgpu_kiq {
struct amdgpu_scratch { struct amdgpu_scratch {
unsigned num_reg; unsigned num_reg;
uint32_t reg_base; uint32_t reg_base;
bool free[32]; uint32_t free_mask;
uint32_t reg[32];
}; };
/* /*
......
...@@ -42,12 +42,12 @@ int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg) ...@@ -42,12 +42,12 @@ int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg)
{ {
int i; int i;
for (i = 0; i < adev->gfx.scratch.num_reg; i++) { i = ffs(adev->gfx.scratch.free_mask);
if (adev->gfx.scratch.free[i]) { if (i != 0 && i <= adev->gfx.scratch.num_reg) {
adev->gfx.scratch.free[i] = false; i--;
*reg = adev->gfx.scratch.reg[i]; adev->gfx.scratch.free_mask &= ~(1u << i);
return 0; *reg = adev->gfx.scratch.reg_base + i;
} return 0;
} }
return -EINVAL; return -EINVAL;
} }
...@@ -62,14 +62,7 @@ int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg) ...@@ -62,14 +62,7 @@ int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg)
*/ */
void amdgpu_gfx_scratch_free(struct amdgpu_device *adev, uint32_t reg) void amdgpu_gfx_scratch_free(struct amdgpu_device *adev, uint32_t reg)
{ {
int i; adev->gfx.scratch.free_mask |= 1u << (reg - adev->gfx.scratch.reg_base);
for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
if (adev->gfx.scratch.reg[i] == reg) {
adev->gfx.scratch.free[i] = true;
return;
}
}
} }
/** /**
......
...@@ -1794,14 +1794,9 @@ static void gfx_v6_0_gpu_init(struct amdgpu_device *adev) ...@@ -1794,14 +1794,9 @@ static void gfx_v6_0_gpu_init(struct amdgpu_device *adev)
static void gfx_v6_0_scratch_init(struct amdgpu_device *adev) static void gfx_v6_0_scratch_init(struct amdgpu_device *adev)
{ {
int i;
adev->gfx.scratch.num_reg = 7; adev->gfx.scratch.num_reg = 7;
adev->gfx.scratch.reg_base = mmSCRATCH_REG0; adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
for (i = 0; i < adev->gfx.scratch.num_reg; i++) { adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
adev->gfx.scratch.free[i] = true;
adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
}
} }
static int gfx_v6_0_ring_test_ring(struct amdgpu_ring *ring) static int gfx_v6_0_ring_test_ring(struct amdgpu_ring *ring)
......
...@@ -2003,14 +2003,9 @@ static void gfx_v7_0_gpu_init(struct amdgpu_device *adev) ...@@ -2003,14 +2003,9 @@ static void gfx_v7_0_gpu_init(struct amdgpu_device *adev)
*/ */
static void gfx_v7_0_scratch_init(struct amdgpu_device *adev) static void gfx_v7_0_scratch_init(struct amdgpu_device *adev)
{ {
int i;
adev->gfx.scratch.num_reg = 7; adev->gfx.scratch.num_reg = 7;
adev->gfx.scratch.reg_base = mmSCRATCH_REG0; adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
for (i = 0; i < adev->gfx.scratch.num_reg; i++) { adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
adev->gfx.scratch.free[i] = true;
adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
}
} }
/** /**
......
...@@ -749,14 +749,9 @@ static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev) ...@@ -749,14 +749,9 @@ static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev)
static void gfx_v8_0_scratch_init(struct amdgpu_device *adev) static void gfx_v8_0_scratch_init(struct amdgpu_device *adev)
{ {
int i;
adev->gfx.scratch.num_reg = 7; adev->gfx.scratch.num_reg = 7;
adev->gfx.scratch.reg_base = mmSCRATCH_REG0; adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
for (i = 0; i < adev->gfx.scratch.num_reg; i++) { adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
adev->gfx.scratch.free[i] = true;
adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
}
} }
static int gfx_v8_0_ring_test_ring(struct amdgpu_ring *ring) static int gfx_v8_0_ring_test_ring(struct amdgpu_ring *ring)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册