diff mbox series

[v3,1/5] ACPI: video: Handle fetching EDID that is longer than 256 bytes

Message ID 20240201221119.42564-2-mario.limonciello@amd.com (mailing list archive)
State New, archived
Headers show
Series Add support for fetching EDID from ACPI _DDC | expand

Commit Message

Mario Limonciello Feb. 1, 2024, 10:11 p.m. UTC
The ACPI specification allows for an EDID to be up to 512 bytes but
the _DDC EDID fetching code will only try up to 256 bytes.

Modify the code to instead start at 512 bytes and work it's way
down instead.

As _DDC is now called up to 4 times on a machine debugging messages
are noisier than necessary.  Decrease from info to debug.

Link: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/Apx_B_Video_Extensions/output-device-specific-methods.html#ddc-return-the-edid-for-this-device
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v1->v2:
 * Use for loop for acpi_video_get_edid()
 * Use one of Rafael's suggestions for acpi_video_device_EDID()
 * Decrease message level too
---
 drivers/acpi/acpi_video.c | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

Comments

Rafael J. Wysocki Feb. 2, 2024, 4:07 p.m. UTC | #1
On Thu, Feb 1, 2024 at 11:11 PM Mario Limonciello
<mario.limonciello@amd.com> wrote:
>
> The ACPI specification allows for an EDID to be up to 512 bytes but
> the _DDC EDID fetching code will only try up to 256 bytes.
>
> Modify the code to instead start at 512 bytes and work it's way
> down instead.
>
> As _DDC is now called up to 4 times on a machine debugging messages
> are noisier than necessary.  Decrease from info to debug.
>
> Link: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/Apx_B_Video_Extensions/output-device-specific-methods.html#ddc-return-the-edid-for-this-device
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

or I can apply it if that's preferred.

Thanks!

> ---
> v1->v2:
>  * Use for loop for acpi_video_get_edid()
>  * Use one of Rafael's suggestions for acpi_video_device_EDID()
>  * Decrease message level too
> ---
>  drivers/acpi/acpi_video.c | 25 +++++++++----------------
>  1 file changed, 9 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
> index 4afdda9db019..3bfd013e09d2 100644
> --- a/drivers/acpi/acpi_video.c
> +++ b/drivers/acpi/acpi_video.c
> @@ -625,12 +625,9 @@ acpi_video_device_EDID(struct acpi_video_device *device,
>
>         if (!device)
>                 return -ENODEV;
> -       if (length == 128)
> -               arg0.integer.value = 1;
> -       else if (length == 256)
> -               arg0.integer.value = 2;
> -       else
> +       if (!length || (length % 128))
>                 return -EINVAL;
> +       arg0.integer.value = length / 128;
>
>         status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
>         if (ACPI_FAILURE(status))
> @@ -641,7 +638,8 @@ acpi_video_device_EDID(struct acpi_video_device *device,
>         if (obj && obj->type == ACPI_TYPE_BUFFER)
>                 *edid = obj;
>         else {
> -               acpi_handle_info(device->dev->handle, "Invalid _DDC data\n");
> +               acpi_handle_debug(device->dev->handle,
> +                                "Invalid _DDC data for length %ld\n", length);
>                 status = -EFAULT;
>                 kfree(obj);
>         }
> @@ -1447,7 +1445,6 @@ int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
>
>         for (i = 0; i < video->attached_count; i++) {
>                 video_device = video->attached_array[i].bind_info;
> -               length = 256;
>
>                 if (!video_device)
>                         continue;
> @@ -1478,18 +1475,14 @@ int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
>                         continue;
>                 }
>
> -               status = acpi_video_device_EDID(video_device, &buffer, length);
> -
> -               if (ACPI_FAILURE(status) || !buffer ||
> -                   buffer->type != ACPI_TYPE_BUFFER) {
> -                       length = 128;
> +               for (length = 512; length > 0; length -= 128) {
>                         status = acpi_video_device_EDID(video_device, &buffer,
>                                                         length);
> -                       if (ACPI_FAILURE(status) || !buffer ||
> -                           buffer->type != ACPI_TYPE_BUFFER) {
> -                               continue;
> -                       }
> +                       if (ACPI_SUCCESS(status))
> +                               break;
>                 }
> +               if (!length)
> +                       continue;
>
>                 *edid = buffer->buffer.pointer;
>                 return length;
> --
> 2.34.1
>
Mario Limonciello Feb. 2, 2024, 4:09 p.m. UTC | #2
On 2/2/2024 10:07, Rafael J. Wysocki wrote:
> On Thu, Feb 1, 2024 at 11:11 PM Mario Limonciello
> <mario.limonciello@amd.com> wrote:
>>
>> The ACPI specification allows for an EDID to be up to 512 bytes but
>> the _DDC EDID fetching code will only try up to 256 bytes.
>>
>> Modify the code to instead start at 512 bytes and work it's way
>> down instead.
>>
>> As _DDC is now called up to 4 times on a machine debugging messages
>> are noisier than necessary.  Decrease from info to debug.
>>
>> Link: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/Apx_B_Video_Extensions/output-device-specific-methods.html#ddc-return-the-edid-for-this-device
>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> 
> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> or I can apply it if that's preferred.

Thanks!

I think go ahead and apply this one to your -next tree.

The rest might take a few weeks to get right and no need to block on this.

> 
> Thanks!
> 
>> ---
>> v1->v2:
>>   * Use for loop for acpi_video_get_edid()
>>   * Use one of Rafael's suggestions for acpi_video_device_EDID()
>>   * Decrease message level too
>> ---
>>   drivers/acpi/acpi_video.c | 25 +++++++++----------------
>>   1 file changed, 9 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
>> index 4afdda9db019..3bfd013e09d2 100644
>> --- a/drivers/acpi/acpi_video.c
>> +++ b/drivers/acpi/acpi_video.c
>> @@ -625,12 +625,9 @@ acpi_video_device_EDID(struct acpi_video_device *device,
>>
>>          if (!device)
>>                  return -ENODEV;
>> -       if (length == 128)
>> -               arg0.integer.value = 1;
>> -       else if (length == 256)
>> -               arg0.integer.value = 2;
>> -       else
>> +       if (!length || (length % 128))
>>                  return -EINVAL;
>> +       arg0.integer.value = length / 128;
>>
>>          status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
>>          if (ACPI_FAILURE(status))
>> @@ -641,7 +638,8 @@ acpi_video_device_EDID(struct acpi_video_device *device,
>>          if (obj && obj->type == ACPI_TYPE_BUFFER)
>>                  *edid = obj;
>>          else {
>> -               acpi_handle_info(device->dev->handle, "Invalid _DDC data\n");
>> +               acpi_handle_debug(device->dev->handle,
>> +                                "Invalid _DDC data for length %ld\n", length);
>>                  status = -EFAULT;
>>                  kfree(obj);
>>          }
>> @@ -1447,7 +1445,6 @@ int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
>>
>>          for (i = 0; i < video->attached_count; i++) {
>>                  video_device = video->attached_array[i].bind_info;
>> -               length = 256;
>>
>>                  if (!video_device)
>>                          continue;
>> @@ -1478,18 +1475,14 @@ int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
>>                          continue;
>>                  }
>>
>> -               status = acpi_video_device_EDID(video_device, &buffer, length);
>> -
>> -               if (ACPI_FAILURE(status) || !buffer ||
>> -                   buffer->type != ACPI_TYPE_BUFFER) {
>> -                       length = 128;
>> +               for (length = 512; length > 0; length -= 128) {
>>                          status = acpi_video_device_EDID(video_device, &buffer,
>>                                                          length);
>> -                       if (ACPI_FAILURE(status) || !buffer ||
>> -                           buffer->type != ACPI_TYPE_BUFFER) {
>> -                               continue;
>> -                       }
>> +                       if (ACPI_SUCCESS(status))
>> +                               break;
>>                  }
>> +               if (!length)
>> +                       continue;
>>
>>                  *edid = buffer->buffer.pointer;
>>                  return length;
>> --
>> 2.34.1
>>
Rafael J. Wysocki Feb. 6, 2024, 7:43 p.m. UTC | #3
On Fri, Feb 2, 2024 at 5:09 PM Mario Limonciello
<mario.limonciello@amd.com> wrote:
>
> On 2/2/2024 10:07, Rafael J. Wysocki wrote:
> > On Thu, Feb 1, 2024 at 11:11 PM Mario Limonciello
> > <mario.limonciello@amd.com> wrote:
> >>
> >> The ACPI specification allows for an EDID to be up to 512 bytes but
> >> the _DDC EDID fetching code will only try up to 256 bytes.
> >>
> >> Modify the code to instead start at 512 bytes and work it's way
> >> down instead.
> >>
> >> As _DDC is now called up to 4 times on a machine debugging messages
> >> are noisier than necessary.  Decrease from info to debug.
> >>
> >> Link: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/Apx_B_Video_Extensions/output-device-specific-methods.html#ddc-return-the-edid-for-this-device
> >> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> >
> > Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >
> > or I can apply it if that's preferred.
>
> Thanks!
>
> I think go ahead and apply this one to your -next tree.

Applied now.

Barring any issues with it, It will get into linux-next in a couple of days.

Thanks!
diff mbox series

Patch

diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index 4afdda9db019..3bfd013e09d2 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -625,12 +625,9 @@  acpi_video_device_EDID(struct acpi_video_device *device,
 
 	if (!device)
 		return -ENODEV;
-	if (length == 128)
-		arg0.integer.value = 1;
-	else if (length == 256)
-		arg0.integer.value = 2;
-	else
+	if (!length || (length % 128))
 		return -EINVAL;
+	arg0.integer.value = length / 128;
 
 	status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
 	if (ACPI_FAILURE(status))
@@ -641,7 +638,8 @@  acpi_video_device_EDID(struct acpi_video_device *device,
 	if (obj && obj->type == ACPI_TYPE_BUFFER)
 		*edid = obj;
 	else {
-		acpi_handle_info(device->dev->handle, "Invalid _DDC data\n");
+		acpi_handle_debug(device->dev->handle,
+				 "Invalid _DDC data for length %ld\n", length);
 		status = -EFAULT;
 		kfree(obj);
 	}
@@ -1447,7 +1445,6 @@  int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
 
 	for (i = 0; i < video->attached_count; i++) {
 		video_device = video->attached_array[i].bind_info;
-		length = 256;
 
 		if (!video_device)
 			continue;
@@ -1478,18 +1475,14 @@  int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
 			continue;
 		}
 
-		status = acpi_video_device_EDID(video_device, &buffer, length);
-
-		if (ACPI_FAILURE(status) || !buffer ||
-		    buffer->type != ACPI_TYPE_BUFFER) {
-			length = 128;
+		for (length = 512; length > 0; length -= 128) {
 			status = acpi_video_device_EDID(video_device, &buffer,
 							length);
-			if (ACPI_FAILURE(status) || !buffer ||
-			    buffer->type != ACPI_TYPE_BUFFER) {
-				continue;
-			}
+			if (ACPI_SUCCESS(status))
+				break;
 		}
+		if (!length)
+			continue;
 
 		*edid = buffer->buffer.pointer;
 		return length;