aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Wallménius <nils.wallmenius@gmail.com>2017-01-16 15:56:48 -0500
committerAlex Deucher <alexander.deucher@amd.com>2017-01-27 11:13:32 -0500
commit50261151a13176a99ee6117dbbb2e557fd0b608b (patch)
treefb6fe0437e2e5e44fa25edc4dd1f6df169da066d
parentcb341a319f7e66f879d69af929c3dadfc1a8f31e (diff)
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: Christian König <christian.koenig@amd.com> Signed-off-by: Nils Wallménius <nils.wallmenius@gmail.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu.h3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c21
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c7
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c7
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c7
5 files changed, 11 insertions, 34 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index ffeda245f38b..953148058bdb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -794,8 +794,7 @@ struct amdgpu_kiq {
794struct amdgpu_scratch { 794struct amdgpu_scratch {
795 unsigned num_reg; 795 unsigned num_reg;
796 uint32_t reg_base; 796 uint32_t reg_base;
797 bool free[32]; 797 uint32_t free_mask;
798 uint32_t reg[32];
799}; 798};
800 799
801/* 800/*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 01a42b6a69a4..19943356cca7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -42,12 +42,12 @@ int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg)
42{ 42{
43 int i; 43 int i;
44 44
45 for (i = 0; i < adev->gfx.scratch.num_reg; i++) { 45 i = ffs(adev->gfx.scratch.free_mask);
46 if (adev->gfx.scratch.free[i]) { 46 if (i != 0 && i <= adev->gfx.scratch.num_reg) {
47 adev->gfx.scratch.free[i] = false; 47 i--;
48 *reg = adev->gfx.scratch.reg[i]; 48 adev->gfx.scratch.free_mask &= ~(1u << i);
49 return 0; 49 *reg = adev->gfx.scratch.reg_base + i;
50 } 50 return 0;
51 } 51 }
52 return -EINVAL; 52 return -EINVAL;
53} 53}
@@ -62,14 +62,7 @@ int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg)
62 */ 62 */
63void amdgpu_gfx_scratch_free(struct amdgpu_device *adev, uint32_t reg) 63void amdgpu_gfx_scratch_free(struct amdgpu_device *adev, uint32_t reg)
64{ 64{
65 int i; 65 adev->gfx.scratch.free_mask |= 1u << (reg - adev->gfx.scratch.reg_base);
66
67 for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
68 if (adev->gfx.scratch.reg[i] == reg) {
69 adev->gfx.scratch.free[i] = true;
70 return;
71 }
72 }
73} 66}
74 67
75/** 68/**
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
index b323f5ef64d2..e0132436c76f 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
@@ -1794,14 +1794,9 @@ static void gfx_v6_0_gpu_init(struct amdgpu_device *adev)
1794 1794
1795static void gfx_v6_0_scratch_init(struct amdgpu_device *adev) 1795static void gfx_v6_0_scratch_init(struct amdgpu_device *adev)
1796{ 1796{
1797 int i;
1798
1799 adev->gfx.scratch.num_reg = 7; 1797 adev->gfx.scratch.num_reg = 7;
1800 adev->gfx.scratch.reg_base = mmSCRATCH_REG0; 1798 adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
1801 for (i = 0; i < adev->gfx.scratch.num_reg; i++) { 1799 adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
1802 adev->gfx.scratch.free[i] = true;
1803 adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
1804 }
1805} 1800}
1806 1801
1807static int gfx_v6_0_ring_test_ring(struct amdgpu_ring *ring) 1802static int gfx_v6_0_ring_test_ring(struct amdgpu_ring *ring)
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
index c4e14015ec5b..cfed6db69b93 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
@@ -2003,14 +2003,9 @@ static void gfx_v7_0_gpu_init(struct amdgpu_device *adev)
2003 */ 2003 */
2004static void gfx_v7_0_scratch_init(struct amdgpu_device *adev) 2004static void gfx_v7_0_scratch_init(struct amdgpu_device *adev)
2005{ 2005{
2006 int i;
2007
2008 adev->gfx.scratch.num_reg = 7; 2006 adev->gfx.scratch.num_reg = 7;
2009 adev->gfx.scratch.reg_base = mmSCRATCH_REG0; 2007 adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
2010 for (i = 0; i < adev->gfx.scratch.num_reg; i++) { 2008 adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
2011 adev->gfx.scratch.free[i] = true;
2012 adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
2013 }
2014} 2009}
2015 2010
2016/** 2011/**
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index c8c45ba952c8..69543d4eef34 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -749,14 +749,9 @@ static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev)
749 749
750static void gfx_v8_0_scratch_init(struct amdgpu_device *adev) 750static void gfx_v8_0_scratch_init(struct amdgpu_device *adev)
751{ 751{
752 int i;
753
754 adev->gfx.scratch.num_reg = 7; 752 adev->gfx.scratch.num_reg = 7;
755 adev->gfx.scratch.reg_base = mmSCRATCH_REG0; 753 adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
756 for (i = 0; i < adev->gfx.scratch.num_reg; i++) { 754 adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
757 adev->gfx.scratch.free[i] = true;
758 adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
759 }
760} 755}
761 756
762static int gfx_v8_0_ring_test_ring(struct amdgpu_ring *ring) 757static int gfx_v8_0_ring_test_ring(struct amdgpu_ring *ring)