diff mbox

drm/radeon: use loop for initializing AFMT blocks

Message ID 1375285828-2487-1-git-send-email-zajec5@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Rafał Miłecki July 31, 2013, 3:50 p.m. UTC
Signed-off-by: Rafa? Mi?ecki <zajec5@gmail.com>
---
Dave/Alex: please decide who picks this patch :)
---
 drivers/gpu/drm/radeon/radeon_display.c |   53 ++++++++++++++-----------------
 1 file changed, 23 insertions(+), 30 deletions(-)

Comments

Alex Deucher July 31, 2013, 8:12 p.m. UTC | #1
On Wed, Jul 31, 2013 at 11:50 AM, Rafa? Mi?ecki <zajec5@gmail.com> wrote:
>
> Signed-off-by: Rafa? Mi?ecki <zajec5@gmail.com>
> ---
> Dave/Alex: please decide who picks this patch :)

I think it might be easier to just assume 6 afmt blocks on all DCE4+
hardware (DCE6 too).  It's makes the logic simpler in the driver.  The
afmt block is tied to the dig encoder so the correct one will always
get selected even if a particular asic has more allocated than it has
physically.

Alex

> ---
>  drivers/gpu/drm/radeon/radeon_display.c |   53 ++++++++++++++-----------------
>  1 file changed, 23 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
> index c2b67b4..31d9fbe 100644
> --- a/drivers/gpu/drm/radeon/radeon_display.c
> +++ b/drivers/gpu/drm/radeon/radeon_display.c
> @@ -1257,38 +1257,31 @@ static void radeon_afmt_init(struct radeon_device *rdev)
>         if (ASIC_IS_DCE6(rdev)) {
>                 /* todo */
>         } else if (ASIC_IS_DCE4(rdev)) {
> +               static uint32_t eg_offsets[] = {
> +                       EVERGREEN_CRTC0_REGISTER_OFFSET,
> +                       EVERGREEN_CRTC1_REGISTER_OFFSET,
> +                       EVERGREEN_CRTC2_REGISTER_OFFSET,
> +                       EVERGREEN_CRTC3_REGISTER_OFFSET,
> +                       EVERGREEN_CRTC4_REGISTER_OFFSET,
> +                       EVERGREEN_CRTC5_REGISTER_OFFSET,
> +               };
> +               int num_afmt;
> +
>                 /* DCE4/5 has 6 audio blocks tied to DIG encoders */
>                 /* DCE4.1 has 2 audio blocks tied to DIG encoders */
> -               rdev->mode_info.afmt[0] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
> -               if (rdev->mode_info.afmt[0]) {
> -                       rdev->mode_info.afmt[0]->offset = EVERGREEN_CRTC0_REGISTER_OFFSET;
> -                       rdev->mode_info.afmt[0]->id = 0;
> -               }
> -               rdev->mode_info.afmt[1] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
> -               if (rdev->mode_info.afmt[1]) {
> -                       rdev->mode_info.afmt[1]->offset = EVERGREEN_CRTC1_REGISTER_OFFSET;
> -                       rdev->mode_info.afmt[1]->id = 1;
> -               }
> -               if (!ASIC_IS_DCE41(rdev)) {
> -                       rdev->mode_info.afmt[2] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
> -                       if (rdev->mode_info.afmt[2]) {
> -                               rdev->mode_info.afmt[2]->offset = EVERGREEN_CRTC2_REGISTER_OFFSET;
> -                               rdev->mode_info.afmt[2]->id = 2;
> -                       }
> -                       rdev->mode_info.afmt[3] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
> -                       if (rdev->mode_info.afmt[3]) {
> -                               rdev->mode_info.afmt[3]->offset = EVERGREEN_CRTC3_REGISTER_OFFSET;
> -                               rdev->mode_info.afmt[3]->id = 3;
> -                       }
> -                       rdev->mode_info.afmt[4] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
> -                       if (rdev->mode_info.afmt[4]) {
> -                               rdev->mode_info.afmt[4]->offset = EVERGREEN_CRTC4_REGISTER_OFFSET;
> -                               rdev->mode_info.afmt[4]->id = 4;
> -                       }
> -                       rdev->mode_info.afmt[5] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
> -                       if (rdev->mode_info.afmt[5]) {
> -                               rdev->mode_info.afmt[5]->offset = EVERGREEN_CRTC5_REGISTER_OFFSET;
> -                               rdev->mode_info.afmt[5]->id = 5;
> +               if (ASIC_IS_DCE5(rdev))
> +                       num_afmt = 6;
> +               else if (ASIC_IS_DCE41(rdev))
> +                       num_afmt = 2;
> +               else /* DCE4 */
> +                       num_afmt = 6;
> +
> +               BUG_ON(num_afmt > ARRAY_SIZE(eg_offsets));
> +               for (i = 0; i < num_afmt; i++) {
> +                       rdev->mode_info.afmt[i] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
> +                       if (rdev->mode_info.afmt[i]) {
> +                               rdev->mode_info.afmt[i]->offset = eg_offsets[i];
> +                               rdev->mode_info.afmt[i]->id = i;
>                         }
>                 }
>         } else if (ASIC_IS_DCE3(rdev)) {
> --
> 1.7.10.4
>
Rafał Miłecki Aug. 1, 2013, 5:54 a.m. UTC | #2
2013/7/31 Alex Deucher <alexdeucher@gmail.com>:
> On Wed, Jul 31, 2013 at 11:50 AM, Rafa? Mi?ecki <zajec5@gmail.com> wrote:
>>
>> Signed-off-by: Rafa? Mi?ecki <zajec5@gmail.com>
>> ---
>> Dave/Alex: please decide who picks this patch :)
>
> I think it might be easier to just assume 6 afmt blocks on all DCE4+
> hardware (DCE6 too).  It's makes the logic simpler in the driver.  The
> afmt block is tied to the dig encoder so the correct one will always
> get selected even if a particular asic has more allocated than it has
> physically.

I'm not sure about idea of allocating memory for parts of hardware
that don't exist (read: wasting some memory). It could be a nice
solution to allocate AFMT blocks depending on the amount of DIG
encoders. Unfortunately, I'm afraid we don't have anything like
"num_dig", do we? We assign "dig->dig_encoder" value using
radeon_atom_pick_dig_encoder, but it just check for encoder/link/crtc.

Any other idea? Or should we just waste some memory? Is this worth it
to avoid this simple
if (ASIC_IS_DCE64(rdev))
	num_afmt = 2;
else if (ASIC_IS_DCE61(rdev))
	num_afmt = 4;
else if (ASIC_IS_DCE6(rdev))
	num_afmt = 6;
else if (ASIC_IS_DCE5(rdev))
	num_afmt = 6;
else if (ASIC_IS_DCE41(rdev))
	num_afmt = 2;
else /* DCE4 */
	num_afmt = 6;
?
Alex Deucher Aug. 1, 2013, 12:51 p.m. UTC | #3
On Thu, Aug 1, 2013 at 1:54 AM, Rafa? Mi?ecki <zajec5@gmail.com> wrote:
> 2013/7/31 Alex Deucher <alexdeucher@gmail.com>:
>> On Wed, Jul 31, 2013 at 11:50 AM, Rafa? Mi?ecki <zajec5@gmail.com> wrote:
>>>
>>> Signed-off-by: Rafa? Mi?ecki <zajec5@gmail.com>
>>> ---
>>> Dave/Alex: please decide who picks this patch :)
>>
>> I think it might be easier to just assume 6 afmt blocks on all DCE4+
>> hardware (DCE6 too).  It's makes the logic simpler in the driver.  The
>> afmt block is tied to the dig encoder so the correct one will always
>> get selected even if a particular asic has more allocated than it has
>> physically.
>
> I'm not sure about idea of allocating memory for parts of hardware
> that don't exist (read: wasting some memory). It could be a nice
> solution to allocate AFMT blocks depending on the amount of DIG
> encoders. Unfortunately, I'm afraid we don't have anything like
> "num_dig", do we? We assign "dig->dig_encoder" value using
> radeon_atom_pick_dig_encoder, but it just check for encoder/link/crtc.
>
> Any other idea? Or should we just waste some memory? Is this worth it

It seems simpler to me, but it's not that big a deal either way.

> to avoid this simple
> if (ASIC_IS_DCE64(rdev))
>         num_afmt = 2;

Need to double check which PHYs oland actually has.  I think it's just
the first two.

> else if (ASIC_IS_DCE61(rdev))
>         num_afmt = 4;

Trinity supports 6 dig encoders.

> else if (ASIC_IS_DCE6(rdev))
>         num_afmt = 6;
> else if (ASIC_IS_DCE5(rdev))
>         num_afmt = 6;
> else if (ASIC_IS_DCE41(rdev))
>         num_afmt = 2;
> else /* DCE4 */
>         num_afmt = 6;
> ?
>
>
> --
> Rafa?
diff mbox

Patch

diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index c2b67b4..31d9fbe 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -1257,38 +1257,31 @@  static void radeon_afmt_init(struct radeon_device *rdev)
 	if (ASIC_IS_DCE6(rdev)) {
 		/* todo */
 	} else if (ASIC_IS_DCE4(rdev)) {
+		static uint32_t eg_offsets[] = {
+			EVERGREEN_CRTC0_REGISTER_OFFSET,
+			EVERGREEN_CRTC1_REGISTER_OFFSET,
+			EVERGREEN_CRTC2_REGISTER_OFFSET,
+			EVERGREEN_CRTC3_REGISTER_OFFSET,
+			EVERGREEN_CRTC4_REGISTER_OFFSET,
+			EVERGREEN_CRTC5_REGISTER_OFFSET,
+		};
+		int num_afmt;
+
 		/* DCE4/5 has 6 audio blocks tied to DIG encoders */
 		/* DCE4.1 has 2 audio blocks tied to DIG encoders */
-		rdev->mode_info.afmt[0] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
-		if (rdev->mode_info.afmt[0]) {
-			rdev->mode_info.afmt[0]->offset = EVERGREEN_CRTC0_REGISTER_OFFSET;
-			rdev->mode_info.afmt[0]->id = 0;
-		}
-		rdev->mode_info.afmt[1] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
-		if (rdev->mode_info.afmt[1]) {
-			rdev->mode_info.afmt[1]->offset = EVERGREEN_CRTC1_REGISTER_OFFSET;
-			rdev->mode_info.afmt[1]->id = 1;
-		}
-		if (!ASIC_IS_DCE41(rdev)) {
-			rdev->mode_info.afmt[2] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
-			if (rdev->mode_info.afmt[2]) {
-				rdev->mode_info.afmt[2]->offset = EVERGREEN_CRTC2_REGISTER_OFFSET;
-				rdev->mode_info.afmt[2]->id = 2;
-			}
-			rdev->mode_info.afmt[3] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
-			if (rdev->mode_info.afmt[3]) {
-				rdev->mode_info.afmt[3]->offset = EVERGREEN_CRTC3_REGISTER_OFFSET;
-				rdev->mode_info.afmt[3]->id = 3;
-			}
-			rdev->mode_info.afmt[4] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
-			if (rdev->mode_info.afmt[4]) {
-				rdev->mode_info.afmt[4]->offset = EVERGREEN_CRTC4_REGISTER_OFFSET;
-				rdev->mode_info.afmt[4]->id = 4;
-			}
-			rdev->mode_info.afmt[5] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
-			if (rdev->mode_info.afmt[5]) {
-				rdev->mode_info.afmt[5]->offset = EVERGREEN_CRTC5_REGISTER_OFFSET;
-				rdev->mode_info.afmt[5]->id = 5;
+		if (ASIC_IS_DCE5(rdev))
+			num_afmt = 6;
+		else if (ASIC_IS_DCE41(rdev))
+			num_afmt = 2;
+		else /* DCE4 */
+			num_afmt = 6;
+
+		BUG_ON(num_afmt > ARRAY_SIZE(eg_offsets));
+		for (i = 0; i < num_afmt; i++) {
+			rdev->mode_info.afmt[i] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL);
+			if (rdev->mode_info.afmt[i]) {
+				rdev->mode_info.afmt[i]->offset = eg_offsets[i];
+				rdev->mode_info.afmt[i]->id = i;
 			}
 		}
 	} else if (ASIC_IS_DCE3(rdev)) {