From: Mario Limonciello <mario.limonciello@amd.com>
To: Jani Nikula <jani.nikula@linux.intel.com>,
amd-gfx@lists.freedesktop.org,
"open list:DRM DRIVERS" <dri-devel@lists.freedesktop.org>,
"open list:ACPI" <linux-acpi@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
Melissa Wen <mwen@igalia.com>, Dave Airlie <airlied@redhat.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Subject: Re: [PATCH v4 1/3] drm: Add drm_get_acpi_edid() helper
Date: Sat, 10 Feb 2024 23:19:23 -0600 [thread overview]
Message-ID: <350ee747-c1bf-4513-aad3-f43b11fcdf0f@amd.com> (raw)
In-Reply-To: <ZcZ1tdXqH90RabvV@phenom.ffwll.local>
On 2/9/2024 12:57, Daniel Vetter wrote:
> On Fri, Feb 09, 2024 at 09:34:13AM -0600, Mario Limonciello wrote:
>> On 2/9/2024 05:07, Daniel Vetter wrote:
>>> On Thu, Feb 08, 2024 at 11:57:11AM +0200, Jani Nikula wrote:
>>>> On Wed, 07 Feb 2024, Mario Limonciello <mario.limonciello@amd.com> wrote:
>>>>> Some manufacturers have intentionally put an EDID that differs from
>>>>> the EDID on the internal panel on laptops. Drivers can call this
>>>>> helper to attempt to fetch the EDID from the BIOS's ACPI _DDC method.
>>>>>
>>>>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
>>>>> ---
>>>>> drivers/gpu/drm/Kconfig | 5 +++
>>>>> drivers/gpu/drm/drm_edid.c | 77 ++++++++++++++++++++++++++++++++++++++
>>>>> include/drm/drm_edid.h | 1 +
>>>>> 3 files changed, 83 insertions(+)
>>>>>
>>>>> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
>>>>> index 6ec33d36f3a4..ec2bb71e8b36 100644
>>>>> --- a/drivers/gpu/drm/Kconfig
>>>>> +++ b/drivers/gpu/drm/Kconfig
>>>>> @@ -21,6 +21,11 @@ menuconfig DRM
>>>>> select KCMP
>>>>> select VIDEO_CMDLINE
>>>>> select VIDEO_NOMODESET
>>>>> + select ACPI_VIDEO if ACPI
>>>>> + select BACKLIGHT_CLASS_DEVICE if ACPI
>>>>> + select INPUT if ACPI
>>>>> + select X86_PLATFORM_DEVICES if ACPI && X86
>>>>> + select ACPI_WMI if ACPI && X86
>>>>
>>>> I think I'll defer to drm maintainers on whether this is okay or
>>>> something to be avoided.
>>>
>>> Uh yeah this is a bit much, and select just messes with everything. Just
>>> #ifdef this in the code with a dummy alternative, if users configure their
>>> kernel without acpi but need it, they get to keep all the pieces.
>>>
>>> Alternatively make a DRM_ACPI_HELPERS symbol, but imo a Kconfig for every
>>> function is also not great. And just using #ifdef in the code also works
>>> for CONFIG_OF, which is exactly the same thing for platforms using dt to
>>> describe hw.
>>>
>>> Also I'd expect ACPI code to already provide dummy functions if ACPI is
>>> provided, so you probably dont even need all that much #ifdef in the code.
>>>
>>> What we defo cant do is select platform/hw stuff just because you enable
>>> CONFIG_DRM.
>>> -Sima
>>
>> The problem was with linking. I'll experiment with #ifdef for the next
>> version.
>
> Ah yes, if e.g. acpi is a module but drm is built-in then it will compile,
> but not link.
>
> You need
>
> depends on (ACPI || ACPI=n)
>
> for this. Looks a bit funny but works for all combinations.
Nope; this fails at link time with this combination:
CONFIG_ACPI=y
CONFIG_ACPI_VIDEO=m
CONFIG_DRM=y
ld: drivers/gpu/drm/drm_edid.o: in function `drm_do_probe_acpi_edid':
drm_edid.c:(.text+0xd34): undefined reference to `acpi_video_get_edid'
make[5]: *** [scripts/Makefile.vmlinux:37: vmlinux] Error 1
So the logical solution is to try
depends on (ACPI_VIDEO || ACPI_VIDEO=n)
But that leads me back to the rabbit hole of why I had the selects moved
to drm instead of drivers in the first place:
drivers/gpu/drm/Kconfig:8:error: recursive dependency detected!
drivers/gpu/drm/Kconfig:8: symbol DRM depends on ACPI_VIDEO
drivers/acpi/Kconfig:213: symbol ACPI_VIDEO depends on
BACKLIGHT_CLASS_DEVICE
drivers/video/backlight/Kconfig:136: symbol BACKLIGHT_CLASS_DEVICE is
selected by DRM_RADEON
drivers/gpu/drm/radeon/Kconfig:3: symbol DRM_RADEON depends on DRM
>
> Since this gets mess it might be useful to have a DRM_ACPI_HELPERS Kconfig
> that controls all this.
How about all those selects that I had in this patch moved to
DRM_ACPI_HELPERS and keep the patch that drops from all the drivers then?
> -Sima
>
>>
>>>
>>>>
>>>>
>>>>> help
>>>>> Kernel-level support for the Direct Rendering Infrastructure (DRI)
>>>>> introduced in XFree86 4.0. If you say Y here, you need to select
>>>>> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
>>>>> index 923c4423151c..c649b4f9fd8e 100644
>>>>> --- a/drivers/gpu/drm/drm_edid.c
>>>>> +++ b/drivers/gpu/drm/drm_edid.c
>>>>> @@ -28,6 +28,7 @@
>>>>> * DEALINGS IN THE SOFTWARE.
>>>>> */
>>>>> +#include <acpi/video.h>
>>>>> #include <linux/bitfield.h>
>>>>> #include <linux/cec.h>
>>>>> #include <linux/hdmi.h>
>>>>> @@ -2188,6 +2189,49 @@ drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
>>>>> return ret == xfers ? 0 : -1;
>>>>> }
>>>>> +/**
>>>>> + * drm_do_probe_acpi_edid() - get EDID information via ACPI _DDC
>>>>> + * @data: struct drm_device
>>>>> + * @buf: EDID data buffer to be filled
>>>>> + * @block: 128 byte EDID block to start fetching from
>>>>> + * @len: EDID data buffer length to fetch
>>>>> + *
>>>>> + * Try to fetch EDID information by calling acpi_video_get_edid() function.
>>>>> + *
>>>>> + * Return: 0 on success or error code on failure.
>>>>> + */
>>>>> +static int
>>>>> +drm_do_probe_acpi_edid(void *data, u8 *buf, unsigned int block, size_t len)
>>>>> +{
>>>>> + struct drm_device *ddev = data;
>>>>> + struct acpi_device *acpidev = ACPI_COMPANION(ddev->dev);
>>>>> + unsigned char start = block * EDID_LENGTH;
>>>>> + void *edid;
>>>>> + int r;
>>>>> +
>>>>> + if (!acpidev)
>>>>> + return -ENODEV;
>>>>> +
>>>>> + /* fetch the entire edid from BIOS */
>>>>> + r = acpi_video_get_edid(acpidev, ACPI_VIDEO_DISPLAY_LCD, -1, &edid);
>>>>> + if (r < 0) {
>>>>> + DRM_DEBUG_KMS("Failed to get EDID from ACPI: %d\n", r);
>>>>> + return -EINVAL;
>>>>> + }
>>>>> + if (len > r || start > r || start + len > r) {
>>>>> + r = -EINVAL;
>>>>> + goto cleanup;
>>>>> + }
>>>>> +
>>>>> + memcpy(buf, edid + start, len);
>>>>> + r = 0;
>>>>> +
>>>>> +cleanup:
>>>>> + kfree(edid);
>>>>> +
>>>>> + return r;
>>>>> +}
>>>>> +
>>>>> static void connector_bad_edid(struct drm_connector *connector,
>>>>> const struct edid *edid, int num_blocks)
>>>>> {
>>>>> @@ -2643,6 +2687,39 @@ struct edid *drm_get_edid(struct drm_connector *connector,
>>>>> }
>>>>> EXPORT_SYMBOL(drm_get_edid);
>>>>> +/**
>>>>> + * drm_get_acpi_edid - get EDID data, if available
>>>>
>>>> I'd prefer all the new EDID API to be named drm_edid_*. Makes a clean
>>>> break from the old API, and is more consistent.
>>>>
>>>> So perhaps drm_edid_read_acpi() to be in line with all the other struct
>>>> drm_edid based EDID reading functions.
>>>>
>>>>> + * @connector: connector we're probing
>>>>> + *
>>>>> + * Use the BIOS to attempt to grab EDID data if possible.
>>>>> + *
>>>>> + * The returned pointer must be freed using drm_edid_free().
>>>>> + *
>>>>> + * Return: Pointer to valid EDID or NULL if we couldn't find any.
>>>>> + */
>>>>> +const struct drm_edid *drm_get_acpi_edid(struct drm_connector *connector)
>>>>> +{
>>>>> + const struct drm_edid *drm_edid;
>>>>> +
>>>>> + switch (connector->connector_type) {
>>>>> + case DRM_MODE_CONNECTOR_LVDS:
>>>>> + case DRM_MODE_CONNECTOR_eDP:
>>>>> + break;
>>>>> + default:
>>>>> + return NULL;
>>>>> + }
>>>>> +
>>>>> + if (connector->force == DRM_FORCE_OFF)
>>>>> + return NULL;
>>>>> +
>>>>> + drm_edid = drm_edid_read_custom(connector, drm_do_probe_acpi_edid, connector->dev);
>>>>> +
>>>>> + /* Note: Do *not* call connector updates here. */
>>>>> +
>>>>> + return drm_edid;
>>>>> +}
>>>>> +EXPORT_SYMBOL(drm_get_acpi_edid);
>>>>> +
>>>>> /**
>>>>> * drm_edid_read_custom - Read EDID data using given EDID block read function
>>>>> * @connector: Connector to use
>>>>> diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
>>>>> index 7923bc00dc7a..ca41be289fc6 100644
>>>>> --- a/include/drm/drm_edid.h
>>>>> +++ b/include/drm/drm_edid.h
>>>>> @@ -410,6 +410,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector,
>>>>> void *data);
>>>>> struct edid *drm_get_edid(struct drm_connector *connector,
>>>>> struct i2c_adapter *adapter);
>>>>> +const struct drm_edid *drm_get_acpi_edid(struct drm_connector *connector);
>>>>
>>>> There's a comment
>>>>
>>>> /* Interface based on struct drm_edid */
>>>>
>>>> towards the end of the file, gathering all the new API under it.
>>>>
>>>> Other than that, LGTM,
>>>>
>>>> BR,
>>>> Jani.
>>>>
>>>>> u32 drm_edid_get_panel_id(struct i2c_adapter *adapter);
>>>>> struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
>>>>> struct i2c_adapter *adapter);
>>>>
>>>> --
>>>> Jani Nikula, Intel
>>>
>>
>
next prev parent reply other threads:[~2024-02-11 5:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-07 22:44 [PATCH v4 0/3] Add drm_get_acpi_edid() helper Mario Limonciello
2024-02-07 22:44 ` [PATCH v4 1/3] drm: " Mario Limonciello
2024-02-08 9:57 ` Jani Nikula
2024-02-08 13:15 ` Maxime Ripard
2024-02-08 14:31 ` Jani Nikula
2024-02-08 18:48 ` Mario Limonciello
2024-02-09 11:07 ` Daniel Vetter
2024-02-09 15:34 ` Mario Limonciello
2024-02-09 18:57 ` Daniel Vetter
2024-02-11 5:19 ` Mario Limonciello [this message]
2024-02-12 11:27 ` Jani Nikula
2024-02-16 16:44 ` Daniel Vetter
2024-02-07 22:44 ` [PATCH v4 2/3] drm/nouveau: Use " Mario Limonciello
2024-02-07 22:44 ` [PATCH v4 3/3] drm: Drop unneeded selects in DRM drivers Mario Limonciello
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=350ee747-c1bf-4513-aad3-f43b11fcdf0f@amd.com \
--to=mario.limonciello@amd.com \
--cc=airlied@redhat.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=mwen@igalia.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox