* [PATCH v5 0/3] Add support for getting EDID over ACPI to DRM
@ 2024-02-11 5:50 Mario Limonciello
2024-02-11 5:50 ` [PATCH v5 1/3] drm: Add support to get EDID from ACPI Mario Limonciello
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Mario Limonciello @ 2024-02-11 5:50 UTC (permalink / raw)
To: amd-gfx, open list:DRM DRIVERS
Cc: open list:ACPI, open list, Melissa Wen, Mark Pearson,
Mario Limonciello
This series adds the ability to fetch the EDID through ACPI for laptop
panels. Drivers need to opt into the behavior.
In this series it's enabled by default for all eDP or LVDS panels with
AMDGPU and certain panels for Nouveau.
Mario Limonciello (3):
drm: Add support to get EDID from ACPI
drm/amd: Fetch the EDID from _DDC if available for eDP
drm/nouveau: Use drm_edid_read_acpi() helper
drivers/gpu/drm/Kconfig | 7 ++
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 +
.../gpu/drm/amd/amdgpu/amdgpu_connectors.c | 3 +
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 8 ++
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +
.../amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 2 +
drivers/gpu/drm/drm_edid.c | 113 ++++++++++++++++--
drivers/gpu/drm/nouveau/nouveau_acpi.c | 27 -----
drivers/gpu/drm/nouveau/nouveau_acpi.h | 2 -
drivers/gpu/drm/nouveau/nouveau_connector.c | 35 +++---
include/drm/drm_connector.h | 6 +
include/drm/drm_edid.h | 1 +
12 files changed, 149 insertions(+), 58 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v5 1/3] drm: Add support to get EDID from ACPI 2024-02-11 5:50 [PATCH v5 0/3] Add support for getting EDID over ACPI to DRM Mario Limonciello @ 2024-02-11 5:50 ` Mario Limonciello 2024-02-12 16:31 ` Mario Limonciello 2024-02-15 14:01 ` Jani Nikula 2024-02-11 5:50 ` [PATCH v5 2/3] drm/amd: Fetch the EDID from _DDC if available for eDP Mario Limonciello 2024-02-11 5:50 ` [PATCH v5 3/3] drm/nouveau: Use drm_edid_read_acpi() helper Mario Limonciello 2 siblings, 2 replies; 8+ messages in thread From: Mario Limonciello @ 2024-02-11 5:50 UTC (permalink / raw) To: amd-gfx, open list:DRM DRIVERS Cc: open list:ACPI, open list, Melissa Wen, Mark Pearson, Mario Limonciello Some manufacturers have intentionally put an EDID that differs from the EDID on the internal panel on laptops. Drivers that prefer to fetch this EDID can set a bit on the drm_connector to indicate that the DRM EDID helpers should try to fetch it and it is preferred if it's present. Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> --- v1->v2: * Split code from previous amdgpu specific helper to generic drm helper. v2->v3: * Add an extra select to fix a variety of randconfig errors found from LKP robot. v3->v4: * Return struct drm_edid v4->v5: * Rename to drm_edid_read_acpi * Drop selects --- drivers/gpu/drm/Kconfig | 7 +++ drivers/gpu/drm/drm_edid.c | 113 +++++++++++++++++++++++++++++++++--- include/drm/drm_connector.h | 6 ++ include/drm/drm_edid.h | 1 + 4 files changed, 119 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 2520db0b776e..a49740c528b9 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -103,6 +103,13 @@ config DRM_KMS_HELPER help CRTC helpers for KMS drivers. +config DRM_ACPI_HELPER + tristate "ACPI support in DRM" + depends on DRM + depends on (ACPI_VIDEO || ACPI_VIDEO=n) + help + ACPI helpers for DRM drivers. + config DRM_DEBUG_DP_MST_TOPOLOGY_REFS bool "Enable refcount backtrace history in the DP MST helpers" depends on STACKTRACE_SUPPORT diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 69c68804023f..096c278b6f66 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,62 @@ 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_connector + * @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_connector *connector = data; + struct drm_device *ddev = connector->dev; + struct acpi_device *acpidev = ACPI_COMPANION(ddev->dev); + unsigned char start = block * EDID_LENGTH; + void *edid; + int r; + + if (!acpidev) + return -ENODEV; + + switch (connector->connector_type) { + case DRM_MODE_CONNECTOR_LVDS: + case DRM_MODE_CONNECTOR_eDP: + break; + default: + return -EINVAL; + } + + /* fetch the entire edid from BIOS */ + if (IS_REACHABLE(CONFIG_DRM_ACPI_HELPER)) { + 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; + } + } else { + r = -EOPNOTSUPP; + } + 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) { @@ -2621,7 +2678,8 @@ EXPORT_SYMBOL(drm_probe_ddc); * @connector: connector we're probing * @adapter: I2C adapter to use for DDC * - * Poke the given I2C channel to grab EDID data if possible. If found, + * If the connector allows it, try to fetch EDID data using ACPI. If not found + * poke the given I2C channel to grab EDID data if possible. If found, * attach it to the connector. * * Return: Pointer to valid EDID or NULL if we couldn't find any. @@ -2629,20 +2687,50 @@ EXPORT_SYMBOL(drm_probe_ddc); struct edid *drm_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter) { - struct edid *edid; + struct edid *edid = NULL; if (connector->force == DRM_FORCE_OFF) return NULL; - if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter)) - return NULL; + if (connector->acpi_edid_allowed) + edid = _drm_do_get_edid(connector, drm_do_probe_acpi_edid, connector, NULL); + + if (!edid) { + if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter)) + return NULL; + edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL); + } - edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL); drm_connector_update_edid_property(connector, edid); return edid; } EXPORT_SYMBOL(drm_get_edid); +/** + * drm_edid_read_acpi - get EDID data, if available + * @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_edid_read_acpi(struct drm_connector *connector) +{ + const struct drm_edid *drm_edid; + + if (connector->force == DRM_FORCE_OFF) + return NULL; + + drm_edid = drm_edid_read_custom(connector, drm_do_probe_acpi_edid, connector); + + /* Note: Do *not* call connector updates here. */ + + return drm_edid; +} +EXPORT_SYMBOL(drm_edid_read_acpi); + /** * drm_edid_read_custom - Read EDID data using given EDID block read function * @connector: Connector to use @@ -2727,10 +2815,11 @@ const struct drm_edid *drm_edid_read_ddc(struct drm_connector *connector, EXPORT_SYMBOL(drm_edid_read_ddc); /** - * drm_edid_read - Read EDID data using connector's I2C adapter + * drm_edid_read - Read EDID data using BIOS or connector's I2C adapter * @connector: Connector to use * - * Read EDID using the connector's I2C adapter. + * Read EDID from BIOS if allowed by connector or by using the connector's + * I2C adapter. * * The EDID may be overridden using debugfs override_edid or firmware EDID * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority @@ -2742,10 +2831,18 @@ EXPORT_SYMBOL(drm_edid_read_ddc); */ const struct drm_edid *drm_edid_read(struct drm_connector *connector) { + const struct drm_edid *drm_edid = NULL; + if (drm_WARN_ON(connector->dev, !connector->ddc)) return NULL; - return drm_edid_read_ddc(connector, connector->ddc); + if (connector->acpi_edid_allowed) + drm_edid = drm_edid_read_acpi(connector); + + if (!drm_edid) + drm_edid = drm_edid_read_ddc(connector, connector->ddc); + + return drm_edid; } EXPORT_SYMBOL(drm_edid_read); diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index fe88d7fc6b8f..74ed47f37a69 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -1886,6 +1886,12 @@ struct drm_connector { /** @hdr_sink_metadata: HDR Metadata Information read from sink */ struct hdr_sink_metadata hdr_sink_metadata; + + /** + * @acpi_edid_allowed: Get the EDID from the BIOS, if available. + * This is only applicable to eDP and LVDS displays. + */ + bool acpi_edid_allowed; }; #define obj_to_connector(x) container_of(x, struct drm_connector, base) diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 518d1b8106c7..38b5e1b5c773 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -463,5 +463,6 @@ bool drm_edid_is_digital(const struct drm_edid *drm_edid); const u8 *drm_find_edid_extension(const struct drm_edid *drm_edid, int ext_id, int *ext_index); +const struct drm_edid *drm_edid_read_acpi(struct drm_connector *connector); #endif /* __DRM_EDID_H__ */ -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v5 1/3] drm: Add support to get EDID from ACPI 2024-02-11 5:50 ` [PATCH v5 1/3] drm: Add support to get EDID from ACPI Mario Limonciello @ 2024-02-12 16:31 ` Mario Limonciello 2024-02-12 21:16 ` Mario Limonciello 2024-02-15 14:01 ` Jani Nikula 1 sibling, 1 reply; 8+ messages in thread From: Mario Limonciello @ 2024-02-12 16:31 UTC (permalink / raw) To: amd-gfx, open list:DRM DRIVERS Cc: open list:ACPI, open list, Melissa Wen, Mark Pearson On 2/10/2024 23:50, Mario Limonciello wrote: > Some manufacturers have intentionally put an EDID that differs from > the EDID on the internal panel on laptops. Drivers that prefer to > fetch this EDID can set a bit on the drm_connector to indicate that > the DRM EDID helpers should try to fetch it and it is preferred if > it's present. > > Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> > --- > v1->v2: > * Split code from previous amdgpu specific helper to generic drm helper. > v2->v3: > * Add an extra select to fix a variety of randconfig errors found from > LKP robot. > v3->v4: > * Return struct drm_edid > v4->v5: > * Rename to drm_edid_read_acpi > * Drop selects > --- > drivers/gpu/drm/Kconfig | 7 +++ > drivers/gpu/drm/drm_edid.c | 113 +++++++++++++++++++++++++++++++++--- > include/drm/drm_connector.h | 6 ++ > include/drm/drm_edid.h | 1 + > 4 files changed, 119 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig > index 2520db0b776e..a49740c528b9 100644 > --- a/drivers/gpu/drm/Kconfig > +++ b/drivers/gpu/drm/Kconfig > @@ -103,6 +103,13 @@ config DRM_KMS_HELPER > help > CRTC helpers for KMS drivers. > > +config DRM_ACPI_HELPER > + tristate "ACPI support in DRM" > + depends on DRM > + depends on (ACPI_VIDEO || ACPI_VIDEO=n) > + help > + ACPI helpers for DRM drivers. > + Unfortunately in my wider testing this still fails with a few combinations. This combination fails to link: CONFIG_ACPI_VIDEO=m CONFIG_DRM_ACPI_HELPER=y CONFIG_DRM=y This combination links but doesn't work because the IS_REACHABLE() fails (-EOPNOTSUPP): CONFIG_ACPI_VIDEO=m CONFIG_DRM_ACPI_HELPER=M CONFIG_DRM=y I'm tempted to split off all of drm_edid to it's own module instead of CONFIG_DRM_ACPI_HELPER which has a depends on (ACPI_VIDEO || ACPI_VIDEIO=n). Or Daniel, any better ideas? > config DRM_DEBUG_DP_MST_TOPOLOGY_REFS > bool "Enable refcount backtrace history in the DP MST helpers" > depends on STACKTRACE_SUPPORT > diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c > index 69c68804023f..096c278b6f66 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,62 @@ 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_connector > + * @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_connector *connector = data; > + struct drm_device *ddev = connector->dev; > + struct acpi_device *acpidev = ACPI_COMPANION(ddev->dev); > + unsigned char start = block * EDID_LENGTH; > + void *edid; > + int r; > + > + if (!acpidev) > + return -ENODEV; > + > + switch (connector->connector_type) { > + case DRM_MODE_CONNECTOR_LVDS: > + case DRM_MODE_CONNECTOR_eDP: > + break; > + default: > + return -EINVAL; > + } > + > + /* fetch the entire edid from BIOS */ > + if (IS_REACHABLE(CONFIG_DRM_ACPI_HELPER)) { > + 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; > + } > + } else { > + r = -EOPNOTSUPP; > + } > + 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) > { > @@ -2621,7 +2678,8 @@ EXPORT_SYMBOL(drm_probe_ddc); > * @connector: connector we're probing > * @adapter: I2C adapter to use for DDC > * > - * Poke the given I2C channel to grab EDID data if possible. If found, > + * If the connector allows it, try to fetch EDID data using ACPI. If not found > + * poke the given I2C channel to grab EDID data if possible. If found, > * attach it to the connector. > * > * Return: Pointer to valid EDID or NULL if we couldn't find any. > @@ -2629,20 +2687,50 @@ EXPORT_SYMBOL(drm_probe_ddc); > struct edid *drm_get_edid(struct drm_connector *connector, > struct i2c_adapter *adapter) > { > - struct edid *edid; > + struct edid *edid = NULL; > > if (connector->force == DRM_FORCE_OFF) > return NULL; > > - if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter)) > - return NULL; > + if (connector->acpi_edid_allowed) > + edid = _drm_do_get_edid(connector, drm_do_probe_acpi_edid, connector, NULL); > + > + if (!edid) { > + if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter)) > + return NULL; > + edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL); > + } > > - edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL); > drm_connector_update_edid_property(connector, edid); > return edid; > } > EXPORT_SYMBOL(drm_get_edid); > > +/** > + * drm_edid_read_acpi - get EDID data, if available > + * @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_edid_read_acpi(struct drm_connector *connector) > +{ > + const struct drm_edid *drm_edid; > + > + if (connector->force == DRM_FORCE_OFF) > + return NULL; > + > + drm_edid = drm_edid_read_custom(connector, drm_do_probe_acpi_edid, connector); > + > + /* Note: Do *not* call connector updates here. */ > + > + return drm_edid; > +} > +EXPORT_SYMBOL(drm_edid_read_acpi); > + > /** > * drm_edid_read_custom - Read EDID data using given EDID block read function > * @connector: Connector to use > @@ -2727,10 +2815,11 @@ const struct drm_edid *drm_edid_read_ddc(struct drm_connector *connector, > EXPORT_SYMBOL(drm_edid_read_ddc); > > /** > - * drm_edid_read - Read EDID data using connector's I2C adapter > + * drm_edid_read - Read EDID data using BIOS or connector's I2C adapter > * @connector: Connector to use > * > - * Read EDID using the connector's I2C adapter. > + * Read EDID from BIOS if allowed by connector or by using the connector's > + * I2C adapter. > * > * The EDID may be overridden using debugfs override_edid or firmware EDID > * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority > @@ -2742,10 +2831,18 @@ EXPORT_SYMBOL(drm_edid_read_ddc); > */ > const struct drm_edid *drm_edid_read(struct drm_connector *connector) > { > + const struct drm_edid *drm_edid = NULL; > + > if (drm_WARN_ON(connector->dev, !connector->ddc)) > return NULL; > > - return drm_edid_read_ddc(connector, connector->ddc); > + if (connector->acpi_edid_allowed) > + drm_edid = drm_edid_read_acpi(connector); > + > + if (!drm_edid) > + drm_edid = drm_edid_read_ddc(connector, connector->ddc); > + > + return drm_edid; > } > EXPORT_SYMBOL(drm_edid_read); > > diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h > index fe88d7fc6b8f..74ed47f37a69 100644 > --- a/include/drm/drm_connector.h > +++ b/include/drm/drm_connector.h > @@ -1886,6 +1886,12 @@ struct drm_connector { > > /** @hdr_sink_metadata: HDR Metadata Information read from sink */ > struct hdr_sink_metadata hdr_sink_metadata; > + > + /** > + * @acpi_edid_allowed: Get the EDID from the BIOS, if available. > + * This is only applicable to eDP and LVDS displays. > + */ > + bool acpi_edid_allowed; > }; > > #define obj_to_connector(x) container_of(x, struct drm_connector, base) > diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h > index 518d1b8106c7..38b5e1b5c773 100644 > --- a/include/drm/drm_edid.h > +++ b/include/drm/drm_edid.h > @@ -463,5 +463,6 @@ bool drm_edid_is_digital(const struct drm_edid *drm_edid); > > const u8 *drm_find_edid_extension(const struct drm_edid *drm_edid, > int ext_id, int *ext_index); > +const struct drm_edid *drm_edid_read_acpi(struct drm_connector *connector); > > #endif /* __DRM_EDID_H__ */ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v5 1/3] drm: Add support to get EDID from ACPI 2024-02-12 16:31 ` Mario Limonciello @ 2024-02-12 21:16 ` Mario Limonciello 0 siblings, 0 replies; 8+ messages in thread From: Mario Limonciello @ 2024-02-12 21:16 UTC (permalink / raw) To: amd-gfx, open list:DRM DRIVERS Cc: open list:ACPI, open list, Melissa Wen, Mark Pearson On 2/12/2024 10:31, Mario Limonciello wrote: > On 2/10/2024 23:50, Mario Limonciello wrote: >> Some manufacturers have intentionally put an EDID that differs from >> the EDID on the internal panel on laptops. Drivers that prefer to >> fetch this EDID can set a bit on the drm_connector to indicate that >> the DRM EDID helpers should try to fetch it and it is preferred if >> it's present. >> >> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> >> --- >> v1->v2: >> * Split code from previous amdgpu specific helper to generic drm >> helper. >> v2->v3: >> * Add an extra select to fix a variety of randconfig errors found from >> LKP robot. >> v3->v4: >> * Return struct drm_edid >> v4->v5: >> * Rename to drm_edid_read_acpi >> * Drop selects >> --- >> drivers/gpu/drm/Kconfig | 7 +++ >> drivers/gpu/drm/drm_edid.c | 113 +++++++++++++++++++++++++++++++++--- >> include/drm/drm_connector.h | 6 ++ >> include/drm/drm_edid.h | 1 + >> 4 files changed, 119 insertions(+), 8 deletions(-) >> >> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig >> index 2520db0b776e..a49740c528b9 100644 >> --- a/drivers/gpu/drm/Kconfig >> +++ b/drivers/gpu/drm/Kconfig >> @@ -103,6 +103,13 @@ config DRM_KMS_HELPER >> help >> CRTC helpers for KMS drivers. >> +config DRM_ACPI_HELPER >> + tristate "ACPI support in DRM" >> + depends on DRM >> + depends on (ACPI_VIDEO || ACPI_VIDEO=n) >> + help >> + ACPI helpers for DRM drivers. >> + > > Unfortunately in my wider testing this still fails with a few combinations. > > This combination fails to link: > > CONFIG_ACPI_VIDEO=m > CONFIG_DRM_ACPI_HELPER=y > CONFIG_DRM=y > > This combination links but doesn't work because the IS_REACHABLE() fails > (-EOPNOTSUPP): > > CONFIG_ACPI_VIDEO=m > CONFIG_DRM_ACPI_HELPER=M > CONFIG_DRM=y > > I'm tempted to split off all of drm_edid to it's own module instead of > CONFIG_DRM_ACPI_HELPER which has a depends on (ACPI_VIDEO || > ACPI_VIDEIO=n). > > Or Daniel, any better ideas? I've come up with a solution that undoes all the select mess in preceding patches. This patch will be swapped around to --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -8,6 +8,7 @@ menuconfig DRM tristate "Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)" depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && HAS_DMA + depends on (ACPI_VIDEO || ACPI_VIDEO=n) select DRM_PANEL_ORIENTATION_QUIRKS select DRM_KMS_HELPER if DRM_FBDEV_EMULATION select FB_CORE if DRM_FBDEV_EMULATION I'll wait a little for any other feedback and then post the updated series. None of the other patches change in any material way. > >> config DRM_DEBUG_DP_MST_TOPOLOGY_REFS >> bool "Enable refcount backtrace history in the DP MST helpers" >> depends on STACKTRACE_SUPPORT >> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c >> index 69c68804023f..096c278b6f66 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,62 @@ 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_connector >> + * @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_connector *connector = data; >> + struct drm_device *ddev = connector->dev; >> + struct acpi_device *acpidev = ACPI_COMPANION(ddev->dev); >> + unsigned char start = block * EDID_LENGTH; >> + void *edid; >> + int r; >> + >> + if (!acpidev) >> + return -ENODEV; >> + >> + switch (connector->connector_type) { >> + case DRM_MODE_CONNECTOR_LVDS: >> + case DRM_MODE_CONNECTOR_eDP: >> + break; >> + default: >> + return -EINVAL; >> + } >> + >> + /* fetch the entire edid from BIOS */ >> + if (IS_REACHABLE(CONFIG_DRM_ACPI_HELPER)) { >> + 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; >> + } >> + } else { >> + r = -EOPNOTSUPP; >> + } >> + 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) >> { >> @@ -2621,7 +2678,8 @@ EXPORT_SYMBOL(drm_probe_ddc); >> * @connector: connector we're probing >> * @adapter: I2C adapter to use for DDC >> * >> - * Poke the given I2C channel to grab EDID data if possible. If found, >> + * If the connector allows it, try to fetch EDID data using ACPI. If >> not found >> + * poke the given I2C channel to grab EDID data if possible. If found, >> * attach it to the connector. >> * >> * Return: Pointer to valid EDID or NULL if we couldn't find any. >> @@ -2629,20 +2687,50 @@ EXPORT_SYMBOL(drm_probe_ddc); >> struct edid *drm_get_edid(struct drm_connector *connector, >> struct i2c_adapter *adapter) >> { >> - struct edid *edid; >> + struct edid *edid = NULL; >> if (connector->force == DRM_FORCE_OFF) >> return NULL; >> - if (connector->force == DRM_FORCE_UNSPECIFIED && >> !drm_probe_ddc(adapter)) >> - return NULL; >> + if (connector->acpi_edid_allowed) >> + edid = _drm_do_get_edid(connector, drm_do_probe_acpi_edid, >> connector, NULL); >> + >> + if (!edid) { >> + if (connector->force == DRM_FORCE_UNSPECIFIED && >> !drm_probe_ddc(adapter)) >> + return NULL; >> + edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, >> adapter, NULL); >> + } >> - edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, >> adapter, NULL); >> drm_connector_update_edid_property(connector, edid); >> return edid; >> } >> EXPORT_SYMBOL(drm_get_edid); >> +/** >> + * drm_edid_read_acpi - get EDID data, if available >> + * @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_edid_read_acpi(struct drm_connector >> *connector) >> +{ >> + const struct drm_edid *drm_edid; >> + >> + if (connector->force == DRM_FORCE_OFF) >> + return NULL; >> + >> + drm_edid = drm_edid_read_custom(connector, >> drm_do_probe_acpi_edid, connector); >> + >> + /* Note: Do *not* call connector updates here. */ >> + >> + return drm_edid; >> +} >> +EXPORT_SYMBOL(drm_edid_read_acpi); >> + >> /** >> * drm_edid_read_custom - Read EDID data using given EDID block read >> function >> * @connector: Connector to use >> @@ -2727,10 +2815,11 @@ const struct drm_edid >> *drm_edid_read_ddc(struct drm_connector *connector, >> EXPORT_SYMBOL(drm_edid_read_ddc); >> /** >> - * drm_edid_read - Read EDID data using connector's I2C adapter >> + * drm_edid_read - Read EDID data using BIOS or connector's I2C adapter >> * @connector: Connector to use >> * >> - * Read EDID using the connector's I2C adapter. >> + * Read EDID from BIOS if allowed by connector or by using the >> connector's >> + * I2C adapter. >> * >> * The EDID may be overridden using debugfs override_edid or >> firmware EDID >> * (drm_edid_load_firmware() and drm.edid_firmware parameter), in >> this priority >> @@ -2742,10 +2831,18 @@ EXPORT_SYMBOL(drm_edid_read_ddc); >> */ >> const struct drm_edid *drm_edid_read(struct drm_connector *connector) >> { >> + const struct drm_edid *drm_edid = NULL; >> + >> if (drm_WARN_ON(connector->dev, !connector->ddc)) >> return NULL; >> - return drm_edid_read_ddc(connector, connector->ddc); >> + if (connector->acpi_edid_allowed) >> + drm_edid = drm_edid_read_acpi(connector); >> + >> + if (!drm_edid) >> + drm_edid = drm_edid_read_ddc(connector, connector->ddc); >> + >> + return drm_edid; >> } >> EXPORT_SYMBOL(drm_edid_read); >> diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h >> index fe88d7fc6b8f..74ed47f37a69 100644 >> --- a/include/drm/drm_connector.h >> +++ b/include/drm/drm_connector.h >> @@ -1886,6 +1886,12 @@ struct drm_connector { >> /** @hdr_sink_metadata: HDR Metadata Information read from sink */ >> struct hdr_sink_metadata hdr_sink_metadata; >> + >> + /** >> + * @acpi_edid_allowed: Get the EDID from the BIOS, if available. >> + * This is only applicable to eDP and LVDS displays. >> + */ >> + bool acpi_edid_allowed; >> }; >> #define obj_to_connector(x) container_of(x, struct drm_connector, base) >> diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h >> index 518d1b8106c7..38b5e1b5c773 100644 >> --- a/include/drm/drm_edid.h >> +++ b/include/drm/drm_edid.h >> @@ -463,5 +463,6 @@ bool drm_edid_is_digital(const struct drm_edid >> *drm_edid); >> const u8 *drm_find_edid_extension(const struct drm_edid *drm_edid, >> int ext_id, int *ext_index); >> +const struct drm_edid *drm_edid_read_acpi(struct drm_connector >> *connector); >> #endif /* __DRM_EDID_H__ */ > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v5 1/3] drm: Add support to get EDID from ACPI 2024-02-11 5:50 ` [PATCH v5 1/3] drm: Add support to get EDID from ACPI Mario Limonciello 2024-02-12 16:31 ` Mario Limonciello @ 2024-02-15 14:01 ` Jani Nikula 2024-02-15 17:58 ` Mario Limonciello 1 sibling, 1 reply; 8+ messages in thread From: Jani Nikula @ 2024-02-15 14:01 UTC (permalink / raw) To: Mario Limonciello, amd-gfx, open list:DRM DRIVERS Cc: open list:ACPI, open list, Melissa Wen, Mark Pearson, Mario Limonciello On Sat, 10 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 that prefer to > fetch this EDID can set a bit on the drm_connector to indicate that > the DRM EDID helpers should try to fetch it and it is preferred if > it's present. > > Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> > --- > v1->v2: > * Split code from previous amdgpu specific helper to generic drm helper. > v2->v3: > * Add an extra select to fix a variety of randconfig errors found from > LKP robot. > v3->v4: > * Return struct drm_edid > v4->v5: > * Rename to drm_edid_read_acpi > * Drop selects > --- > drivers/gpu/drm/Kconfig | 7 +++ > drivers/gpu/drm/drm_edid.c | 113 +++++++++++++++++++++++++++++++++--- > include/drm/drm_connector.h | 6 ++ > include/drm/drm_edid.h | 1 + > 4 files changed, 119 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig > index 2520db0b776e..a49740c528b9 100644 > --- a/drivers/gpu/drm/Kconfig > +++ b/drivers/gpu/drm/Kconfig > @@ -103,6 +103,13 @@ config DRM_KMS_HELPER > help > CRTC helpers for KMS drivers. > > +config DRM_ACPI_HELPER > + tristate "ACPI support in DRM" > + depends on DRM > + depends on (ACPI_VIDEO || ACPI_VIDEO=n) > + help > + ACPI helpers for DRM drivers. > + > config DRM_DEBUG_DP_MST_TOPOLOGY_REFS > bool "Enable refcount backtrace history in the DP MST helpers" > depends on STACKTRACE_SUPPORT > diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c > index 69c68804023f..096c278b6f66 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,62 @@ 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_connector > + * @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_connector *connector = data; > + struct drm_device *ddev = connector->dev; > + struct acpi_device *acpidev = ACPI_COMPANION(ddev->dev); > + unsigned char start = block * EDID_LENGTH; > + void *edid; > + int r; > + > + if (!acpidev) > + return -ENODEV; > + > + switch (connector->connector_type) { > + case DRM_MODE_CONNECTOR_LVDS: > + case DRM_MODE_CONNECTOR_eDP: > + break; > + default: > + return -EINVAL; > + } > + > + /* fetch the entire edid from BIOS */ > + if (IS_REACHABLE(CONFIG_DRM_ACPI_HELPER)) { > + 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; > + } > + } else { > + r = -EOPNOTSUPP; > + } > + 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) > { > @@ -2621,7 +2678,8 @@ EXPORT_SYMBOL(drm_probe_ddc); > * @connector: connector we're probing > * @adapter: I2C adapter to use for DDC > * > - * Poke the given I2C channel to grab EDID data if possible. If found, > + * If the connector allows it, try to fetch EDID data using ACPI. If not found > + * poke the given I2C channel to grab EDID data if possible. If found, > * attach it to the connector. > * > * Return: Pointer to valid EDID or NULL if we couldn't find any. > @@ -2629,20 +2687,50 @@ EXPORT_SYMBOL(drm_probe_ddc); > struct edid *drm_get_edid(struct drm_connector *connector, > struct i2c_adapter *adapter) > { > - struct edid *edid; > + struct edid *edid = NULL; > > if (connector->force == DRM_FORCE_OFF) > return NULL; > > - if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter)) > - return NULL; > + if (connector->acpi_edid_allowed) > + edid = _drm_do_get_edid(connector, drm_do_probe_acpi_edid, connector, NULL); > + > + if (!edid) { > + if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter)) > + return NULL; > + edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL); > + } Hmm. So do you want the presence of ACPI EDID to determine whether the display is there or not? Note how the override and firmware EDID mechanisms only override the EDID *contents*. They are orthogonal from connector forcing. So you can override the EDID, but still rely on the DDC probe to determine if the display is there. The question is, how likely is it that the ACPI EDID is used not just because the actual EDID is bogus, but also because the display just doesn't respond to DDC at all? If possible, I'd like ACPI EDID to follow the override/firmware EDID semantics on this. > > - edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL); > drm_connector_update_edid_property(connector, edid); > return edid; > } > EXPORT_SYMBOL(drm_get_edid); > > +/** > + * drm_edid_read_acpi - get EDID data, if available > + * @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_edid_read_acpi(struct drm_connector *connector) > +{ > + const struct drm_edid *drm_edid; > + > + if (connector->force == DRM_FORCE_OFF) > + return NULL; If the caller handled all the connector->force stuff, this could be dropped. > + > + drm_edid = drm_edid_read_custom(connector, drm_do_probe_acpi_edid, connector); > + > + /* Note: Do *not* call connector updates here. */ > + > + return drm_edid; > +} > +EXPORT_SYMBOL(drm_edid_read_acpi); > + > /** > * drm_edid_read_custom - Read EDID data using given EDID block read function > * @connector: Connector to use > @@ -2727,10 +2815,11 @@ const struct drm_edid *drm_edid_read_ddc(struct drm_connector *connector, > EXPORT_SYMBOL(drm_edid_read_ddc); > > /** > - * drm_edid_read - Read EDID data using connector's I2C adapter > + * drm_edid_read - Read EDID data using BIOS or connector's I2C adapter > * @connector: Connector to use > * > - * Read EDID using the connector's I2C adapter. > + * Read EDID from BIOS if allowed by connector or by using the connector's > + * I2C adapter. > * > * The EDID may be overridden using debugfs override_edid or firmware EDID > * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority > @@ -2742,10 +2831,18 @@ EXPORT_SYMBOL(drm_edid_read_ddc); > */ > const struct drm_edid *drm_edid_read(struct drm_connector *connector) > { > + const struct drm_edid *drm_edid = NULL; > + > if (drm_WARN_ON(connector->dev, !connector->ddc)) > return NULL; > > - return drm_edid_read_ddc(connector, connector->ddc); > + if (connector->acpi_edid_allowed) > + drm_edid = drm_edid_read_acpi(connector); > + > + if (!drm_edid) > + drm_edid = drm_edid_read_ddc(connector, connector->ddc); This should be in drm_edid_read_ddc() not drm_edid_read(). Please let's not make the two behave any different. It would be really weird if one had an ACPI check and the other not. > + > + return drm_edid; > } > EXPORT_SYMBOL(drm_edid_read); > > diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h > index fe88d7fc6b8f..74ed47f37a69 100644 > --- a/include/drm/drm_connector.h > +++ b/include/drm/drm_connector.h > @@ -1886,6 +1886,12 @@ struct drm_connector { > > /** @hdr_sink_metadata: HDR Metadata Information read from sink */ > struct hdr_sink_metadata hdr_sink_metadata; > + > + /** > + * @acpi_edid_allowed: Get the EDID from the BIOS, if available. > + * This is only applicable to eDP and LVDS displays. > + */ > + bool acpi_edid_allowed; > }; > > #define obj_to_connector(x) container_of(x, struct drm_connector, base) > diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h > index 518d1b8106c7..38b5e1b5c773 100644 > --- a/include/drm/drm_edid.h > +++ b/include/drm/drm_edid.h > @@ -463,5 +463,6 @@ bool drm_edid_is_digital(const struct drm_edid *drm_edid); > > const u8 *drm_find_edid_extension(const struct drm_edid *drm_edid, > int ext_id, int *ext_index); > +const struct drm_edid *drm_edid_read_acpi(struct drm_connector *connector); > > #endif /* __DRM_EDID_H__ */ -- Jani Nikula, Intel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v5 1/3] drm: Add support to get EDID from ACPI 2024-02-15 14:01 ` Jani Nikula @ 2024-02-15 17:58 ` Mario Limonciello 0 siblings, 0 replies; 8+ messages in thread From: Mario Limonciello @ 2024-02-15 17:58 UTC (permalink / raw) To: Jani Nikula, amd-gfx, open list:DRM DRIVERS Cc: open list:ACPI, open list, Melissa Wen, Mark Pearson On 2/15/2024 08:01, Jani Nikula wrote: > On Sat, 10 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 that prefer to >> fetch this EDID can set a bit on the drm_connector to indicate that >> the DRM EDID helpers should try to fetch it and it is preferred if >> it's present. >> >> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> >> --- >> v1->v2: >> * Split code from previous amdgpu specific helper to generic drm helper. >> v2->v3: >> * Add an extra select to fix a variety of randconfig errors found from >> LKP robot. >> v3->v4: >> * Return struct drm_edid >> v4->v5: >> * Rename to drm_edid_read_acpi >> * Drop selects >> --- >> drivers/gpu/drm/Kconfig | 7 +++ >> drivers/gpu/drm/drm_edid.c | 113 +++++++++++++++++++++++++++++++++--- >> include/drm/drm_connector.h | 6 ++ >> include/drm/drm_edid.h | 1 + >> 4 files changed, 119 insertions(+), 8 deletions(-) >> >> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig >> index 2520db0b776e..a49740c528b9 100644 >> --- a/drivers/gpu/drm/Kconfig >> +++ b/drivers/gpu/drm/Kconfig >> @@ -103,6 +103,13 @@ config DRM_KMS_HELPER >> help >> CRTC helpers for KMS drivers. >> >> +config DRM_ACPI_HELPER >> + tristate "ACPI support in DRM" >> + depends on DRM >> + depends on (ACPI_VIDEO || ACPI_VIDEO=n) >> + help >> + ACPI helpers for DRM drivers. >> + >> config DRM_DEBUG_DP_MST_TOPOLOGY_REFS >> bool "Enable refcount backtrace history in the DP MST helpers" >> depends on STACKTRACE_SUPPORT >> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c >> index 69c68804023f..096c278b6f66 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,62 @@ 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_connector >> + * @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_connector *connector = data; >> + struct drm_device *ddev = connector->dev; >> + struct acpi_device *acpidev = ACPI_COMPANION(ddev->dev); >> + unsigned char start = block * EDID_LENGTH; >> + void *edid; >> + int r; >> + >> + if (!acpidev) >> + return -ENODEV; >> + >> + switch (connector->connector_type) { >> + case DRM_MODE_CONNECTOR_LVDS: >> + case DRM_MODE_CONNECTOR_eDP: >> + break; >> + default: >> + return -EINVAL; >> + } >> + >> + /* fetch the entire edid from BIOS */ >> + if (IS_REACHABLE(CONFIG_DRM_ACPI_HELPER)) { >> + 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; >> + } >> + } else { >> + r = -EOPNOTSUPP; >> + } >> + 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) >> { >> @@ -2621,7 +2678,8 @@ EXPORT_SYMBOL(drm_probe_ddc); >> * @connector: connector we're probing >> * @adapter: I2C adapter to use for DDC >> * >> - * Poke the given I2C channel to grab EDID data if possible. If found, >> + * If the connector allows it, try to fetch EDID data using ACPI. If not found >> + * poke the given I2C channel to grab EDID data if possible. If found, >> * attach it to the connector. >> * >> * Return: Pointer to valid EDID or NULL if we couldn't find any. >> @@ -2629,20 +2687,50 @@ EXPORT_SYMBOL(drm_probe_ddc); >> struct edid *drm_get_edid(struct drm_connector *connector, >> struct i2c_adapter *adapter) >> { >> - struct edid *edid; >> + struct edid *edid = NULL; >> >> if (connector->force == DRM_FORCE_OFF) >> return NULL; >> >> - if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter)) >> - return NULL; >> + if (connector->acpi_edid_allowed) >> + edid = _drm_do_get_edid(connector, drm_do_probe_acpi_edid, connector, NULL); >> + >> + if (!edid) { >> + if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter)) >> + return NULL; >> + edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL); >> + } > > Hmm. So do you want the presence of ACPI EDID to determine whether the > display is there or not? > > Note how the override and firmware EDID mechanisms only override the > EDID *contents*. They are orthogonal from connector forcing. So you can > override the EDID, but still rely on the DDC probe to determine if the > display is there. > > The question is, how likely is it that the ACPI EDID is used not just > because the actual EDID is bogus, but also because the display just > doesn't respond to DDC at all? > The cases that prompted this the panel "responds" to DDC fine, but the EDID data doesn't match what is expected to be used which leads to other unexpected functional problems. > If possible, I'd like ACPI EDID to follow the override/firmware EDID > semantics on this. > So basically probe with DDC but if the driver specifies on the connector to use ACPI if present then try that (similar to how override is only used if specified by the user)? >> >> - edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL); >> drm_connector_update_edid_property(connector, edid); >> return edid; >> } >> EXPORT_SYMBOL(drm_get_edid); >> >> +/** >> + * drm_edid_read_acpi - get EDID data, if available >> + * @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_edid_read_acpi(struct drm_connector *connector) >> +{ >> + const struct drm_edid *drm_edid; >> + >> + if (connector->force == DRM_FORCE_OFF) >> + return NULL; > > If the caller handled all the connector->force stuff, this could be > dropped. > >> + >> + drm_edid = drm_edid_read_custom(connector, drm_do_probe_acpi_edid, connector); >> + >> + /* Note: Do *not* call connector updates here. */ >> + >> + return drm_edid; >> +} >> +EXPORT_SYMBOL(drm_edid_read_acpi); >> + >> /** >> * drm_edid_read_custom - Read EDID data using given EDID block read function >> * @connector: Connector to use >> @@ -2727,10 +2815,11 @@ const struct drm_edid *drm_edid_read_ddc(struct drm_connector *connector, >> EXPORT_SYMBOL(drm_edid_read_ddc); >> >> /** >> - * drm_edid_read - Read EDID data using connector's I2C adapter >> + * drm_edid_read - Read EDID data using BIOS or connector's I2C adapter >> * @connector: Connector to use >> * >> - * Read EDID using the connector's I2C adapter. >> + * Read EDID from BIOS if allowed by connector or by using the connector's >> + * I2C adapter. >> * >> * The EDID may be overridden using debugfs override_edid or firmware EDID >> * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority >> @@ -2742,10 +2831,18 @@ EXPORT_SYMBOL(drm_edid_read_ddc); >> */ >> const struct drm_edid *drm_edid_read(struct drm_connector *connector) >> { >> + const struct drm_edid *drm_edid = NULL; >> + >> if (drm_WARN_ON(connector->dev, !connector->ddc)) >> return NULL; >> >> - return drm_edid_read_ddc(connector, connector->ddc); >> + if (connector->acpi_edid_allowed) >> + drm_edid = drm_edid_read_acpi(connector); >> + >> + if (!drm_edid) >> + drm_edid = drm_edid_read_ddc(connector, connector->ddc); > > This should be in drm_edid_read_ddc() not drm_edid_read(). Please let's > not make the two behave any different. It would be really weird if one > had an ACPI check and the other not. OK, I'll move things around. > >> + >> + return drm_edid; >> } >> EXPORT_SYMBOL(drm_edid_read); >> >> diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h >> index fe88d7fc6b8f..74ed47f37a69 100644 >> --- a/include/drm/drm_connector.h >> +++ b/include/drm/drm_connector.h >> @@ -1886,6 +1886,12 @@ struct drm_connector { >> >> /** @hdr_sink_metadata: HDR Metadata Information read from sink */ >> struct hdr_sink_metadata hdr_sink_metadata; >> + >> + /** >> + * @acpi_edid_allowed: Get the EDID from the BIOS, if available. >> + * This is only applicable to eDP and LVDS displays. >> + */ >> + bool acpi_edid_allowed; >> }; >> >> #define obj_to_connector(x) container_of(x, struct drm_connector, base) >> diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h >> index 518d1b8106c7..38b5e1b5c773 100644 >> --- a/include/drm/drm_edid.h >> +++ b/include/drm/drm_edid.h >> @@ -463,5 +463,6 @@ bool drm_edid_is_digital(const struct drm_edid *drm_edid); >> >> const u8 *drm_find_edid_extension(const struct drm_edid *drm_edid, >> int ext_id, int *ext_index); >> +const struct drm_edid *drm_edid_read_acpi(struct drm_connector *connector); >> >> #endif /* __DRM_EDID_H__ */ > ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v5 2/3] drm/amd: Fetch the EDID from _DDC if available for eDP 2024-02-11 5:50 [PATCH v5 0/3] Add support for getting EDID over ACPI to DRM Mario Limonciello 2024-02-11 5:50 ` [PATCH v5 1/3] drm: Add support to get EDID from ACPI Mario Limonciello @ 2024-02-11 5:50 ` Mario Limonciello 2024-02-11 5:50 ` [PATCH v5 3/3] drm/nouveau: Use drm_edid_read_acpi() helper Mario Limonciello 2 siblings, 0 replies; 8+ messages in thread From: Mario Limonciello @ 2024-02-11 5:50 UTC (permalink / raw) To: amd-gfx, open list:DRM DRIVERS Cc: open list:ACPI, open list, Melissa Wen, Mark Pearson, Mario Limonciello Some manufacturers have intentionally put an EDID that differs from the EDID on the internal panel on laptops. Attempt to fetch this EDID if it exists and prefer it over the EDID that is provided by the panel. If a user prefers to use the EDID from the panel, offer a module parameter that would disable this. Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> --- v4->v5: * rebase on v5 changes --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 8 ++++++++ drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 +++- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 2 ++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 543ed9de5a6d..399885251714 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -217,6 +217,7 @@ extern int amdgpu_smartshift_bias; extern int amdgpu_use_xgmi_p2p; extern int amdgpu_mtype_local; extern bool enforce_isolation; +extern bool acpi_edid; #ifdef CONFIG_HSA_AMD extern int sched_policy; extern bool debug_evictions; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c index 9caba10315a8..9165a199ac9b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c @@ -281,6 +281,9 @@ static void amdgpu_connector_get_edid(struct drm_connector *connector) if (amdgpu_connector->edid) return; + /* if the BIOS specifies the EDID via _DDC, prefer this */ + connector->acpi_edid_allowed = acpi_edid; + /* on hw with routers, select right port */ if (amdgpu_connector->router.ddc_valid) amdgpu_i2c_router_select_ddc_port(amdgpu_connector); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index edc042db4ea8..123f1128d14e 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -166,6 +166,7 @@ uint amdgpu_sdma_phase_quantum = 32; char *amdgpu_disable_cu; char *amdgpu_virtual_display; bool enforce_isolation; +bool acpi_edid = true; /* * OverDrive(bit 14) disabled by default * GFX DCS(bit 19) disabled by default @@ -991,6 +992,13 @@ MODULE_PARM_DESC(wbrf, "Enable Wifi RFI interference mitigation (0 = disabled, 1 = enabled, -1 = auto(default)"); module_param_named(wbrf, amdgpu_wbrf, int, 0444); +/** + * DOC: acpi_edid (bool) + * Try to fetch EDID for eDP display from BIOS using ACPI _DDC method. + */ +module_param(acpi_edid, bool, 0444); +MODULE_PARM_DESC(acpi_edid, "Fetch EDID for eDP display from BIOS"); + /* These devices are not supported by amdgpu. * They are supported by the mach64, r128, radeon drivers */ diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index ed90fc8fee9f..0b3a19d3d43a 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -6619,8 +6619,10 @@ static void amdgpu_dm_connector_funcs_force(struct drm_connector *connector) * Note: drm_get_edid gets edid in the following order: * 1) override EDID if set via edid_override debugfs, * 2) firmware EDID if set via edid_firmware module parameter - * 3) regular DDC read. + * 3) ACPI EDID if allowed via module parameter + * 4) regular DDC read. */ + connector->acpi_edid_allowed = acpi_edid; edid = drm_get_edid(connector, &amdgpu_connector->ddc_bus->aux.ddc); if (!edid) { DRM_ERROR("No EDID found on connector: %s.\n", connector->name); diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c index 85b7f58a7f35..d570a1b6141b 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c @@ -910,6 +910,8 @@ enum dc_edid_status dm_helpers_read_local_edid( * do check sum and retry to make sure read correct edid. */ do { + /* prefer ACPI over panel for eDP */ + connector->acpi_edid_allowed = acpi_edid; edid = drm_get_edid(&aconnector->base, ddc); -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v5 3/3] drm/nouveau: Use drm_edid_read_acpi() helper 2024-02-11 5:50 [PATCH v5 0/3] Add support for getting EDID over ACPI to DRM Mario Limonciello 2024-02-11 5:50 ` [PATCH v5 1/3] drm: Add support to get EDID from ACPI Mario Limonciello 2024-02-11 5:50 ` [PATCH v5 2/3] drm/amd: Fetch the EDID from _DDC if available for eDP Mario Limonciello @ 2024-02-11 5:50 ` Mario Limonciello 2 siblings, 0 replies; 8+ messages in thread From: Mario Limonciello @ 2024-02-11 5:50 UTC (permalink / raw) To: amd-gfx, open list:DRM DRIVERS Cc: open list:ACPI, open list, Melissa Wen, Mark Pearson, Mario Limonciello Rather than inventing a wrapper to acpi_video_get_edid() use the one provided by drm. This fixes two problems: 1. A memory leak that the memory provided by the ACPI call was never freed. 2. Validation of the BIOS provided blob. Convert the usage in nouveau_connector_detect_lvds() to use struct drm_edid at the same time. Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> --- v1->v2: * New patch v3->v4: * Rebase on v4 changes v4->v5: * Rebase on v5 changes --- drivers/gpu/drm/nouveau/nouveau_acpi.c | 27 ---------------- drivers/gpu/drm/nouveau/nouveau_acpi.h | 2 -- drivers/gpu/drm/nouveau/nouveau_connector.c | 35 +++++++++------------ 3 files changed, 14 insertions(+), 50 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_acpi.c b/drivers/gpu/drm/nouveau/nouveau_acpi.c index 8f0c69aad248..de9daafb3fbb 100644 --- a/drivers/gpu/drm/nouveau/nouveau_acpi.c +++ b/drivers/gpu/drm/nouveau/nouveau_acpi.c @@ -360,33 +360,6 @@ void nouveau_unregister_dsm_handler(void) {} void nouveau_switcheroo_optimus_dsm(void) {} #endif -void * -nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) -{ - struct acpi_device *acpidev; - int type, ret; - void *edid; - - switch (connector->connector_type) { - case DRM_MODE_CONNECTOR_LVDS: - case DRM_MODE_CONNECTOR_eDP: - type = ACPI_VIDEO_DISPLAY_LCD; - break; - default: - return NULL; - } - - acpidev = ACPI_COMPANION(dev->dev); - if (!acpidev) - return NULL; - - ret = acpi_video_get_edid(acpidev, type, -1, &edid); - if (ret < 0) - return NULL; - - return kmemdup(edid, EDID_LENGTH, GFP_KERNEL); -} - bool nouveau_acpi_video_backlight_use_native(void) { return acpi_video_backlight_use_native(); diff --git a/drivers/gpu/drm/nouveau/nouveau_acpi.h b/drivers/gpu/drm/nouveau/nouveau_acpi.h index e39dd8b94b8b..6a3def8e6cca 100644 --- a/drivers/gpu/drm/nouveau/nouveau_acpi.h +++ b/drivers/gpu/drm/nouveau/nouveau_acpi.h @@ -10,7 +10,6 @@ bool nouveau_is_v1_dsm(void); void nouveau_register_dsm_handler(void); void nouveau_unregister_dsm_handler(void); void nouveau_switcheroo_optimus_dsm(void); -void *nouveau_acpi_edid(struct drm_device *, struct drm_connector *); bool nouveau_acpi_video_backlight_use_native(void); void nouveau_acpi_video_register_backlight(void); #else @@ -19,7 +18,6 @@ static inline bool nouveau_is_v1_dsm(void) { return false; }; static inline void nouveau_register_dsm_handler(void) {} static inline void nouveau_unregister_dsm_handler(void) {} static inline void nouveau_switcheroo_optimus_dsm(void) {} -static inline void *nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) { return NULL; } static inline bool nouveau_acpi_video_backlight_use_native(void) { return true; } static inline void nouveau_acpi_video_register_backlight(void) {} #endif diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c index 856b3ef5edb8..492035dc8453 100644 --- a/drivers/gpu/drm/nouveau/nouveau_connector.c +++ b/drivers/gpu/drm/nouveau/nouveau_connector.c @@ -687,22 +687,13 @@ nouveau_connector_detect_lvds(struct drm_connector *connector, bool force) struct nouveau_drm *drm = nouveau_drm(dev); struct nouveau_connector *nv_connector = nouveau_connector(connector); struct nouveau_encoder *nv_encoder = NULL; - struct edid *edid = NULL; + const struct drm_edid *drm_edid = NULL; enum drm_connector_status status = connector_status_disconnected; nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS); if (!nv_encoder) goto out; - /* Try retrieving EDID via DDC */ - if (!drm->vbios.fp_no_ddc) { - status = nouveau_connector_detect(connector, force); - if (status == connector_status_connected) { - edid = nv_connector->edid; - goto out; - } - } - /* On some laptops (Sony, i'm looking at you) there appears to * be no direct way of accessing the panel's EDID. The only * option available to us appears to be to ask ACPI for help.. @@ -712,10 +703,14 @@ nouveau_connector_detect_lvds(struct drm_connector *connector, bool force) * the nouveau decides an entry in the VBIOS FP mode table is * valid - it's not (rh#613284) */ - if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) { - edid = nouveau_acpi_edid(dev, connector); - if (edid) { - status = connector_status_connected; + if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) + connector->acpi_edid_allowed = true; + + /* Try retrieving EDID via BIOS or DDC */ + if (!drm->vbios.fp_no_ddc || nv_encoder->dcb->lvdsconf.use_acpi_for_edid) { + status = nouveau_connector_detect(connector, force); + if (status == connector_status_connected) { + drm_edid = drm_edid_alloc(nv_connector->edid, EDID_LENGTH); goto out; } } @@ -734,12 +729,9 @@ nouveau_connector_detect_lvds(struct drm_connector *connector, bool force) * stored for the panel stored in them. */ if (!drm->vbios.fp_no_ddc) { - edid = (struct edid *)nouveau_bios_embedded_edid(dev); - if (edid) { - edid = kmemdup(edid, EDID_LENGTH, GFP_KERNEL); - if (edid) - status = connector_status_connected; - } + drm_edid = drm_edid_alloc(nouveau_bios_embedded_edid(dev), EDID_LENGTH); + if (drm_edid) + status = connector_status_connected; } out: @@ -750,7 +742,8 @@ nouveau_connector_detect_lvds(struct drm_connector *connector, bool force) status = connector_status_unknown; #endif - nouveau_connector_set_edid(nv_connector, edid); + drm_edid_connector_update(connector, drm_edid); + drm_edid_free(drm_edid); if (nv_encoder) nouveau_connector_set_encoder(connector, nv_encoder); return status; -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-02-15 17:58 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-02-11 5:50 [PATCH v5 0/3] Add support for getting EDID over ACPI to DRM Mario Limonciello 2024-02-11 5:50 ` [PATCH v5 1/3] drm: Add support to get EDID from ACPI Mario Limonciello 2024-02-12 16:31 ` Mario Limonciello 2024-02-12 21:16 ` Mario Limonciello 2024-02-15 14:01 ` Jani Nikula 2024-02-15 17:58 ` Mario Limonciello 2024-02-11 5:50 ` [PATCH v5 2/3] drm/amd: Fetch the EDID from _DDC if available for eDP Mario Limonciello 2024-02-11 5:50 ` [PATCH v5 3/3] drm/nouveau: Use drm_edid_read_acpi() helper Mario Limonciello
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox