diff mbox series

[RFC,v2,17/18] drm/vkms: Introduce config for connector EDID

Message ID 20241122-google-remove-crtc-index-from-parameter-v2-17-81540742535a@bootlin.com (mailing list archive)
State New
Headers show
Series drm/vkms: Introduce detailed configuration | expand

Commit Message

Louis Chauvet Nov. 22, 2024, 5:20 p.m. UTC
To properly test the EDID reading without using the DRM override, add an
option to configure the EDID for a connector.

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
 drivers/gpu/drm/vkms/vkms_config.c |  1 +
 drivers/gpu/drm/vkms/vkms_config.h |  2 ++
 drivers/gpu/drm/vkms/vkms_output.c | 37 ++++++++++++++++++++++++++++++++++---
 3 files changed, 37 insertions(+), 3 deletions(-)

Comments

Ian Forbes Nov. 22, 2024, 9:28 p.m. UTC | #1
I didn't see a `drm_connector_attach_edid_property` call in this
series. Did you forget this? Virtual connectors don't have this
property by default.

Ian,
Louis Chauvet Nov. 23, 2024, 10:45 a.m. UTC | #2
Le 22 novembre 2024 21:28:00 UTC, Ian Forbes <ian.forbes@broadcom.com> a écrit :
>I didn't see a `drm_connector_attach_edid_property` call in this
>series. Did you forget this? Virtual connectors don't have this
>property by default.

Hello Ian,

You are right; I did not call this function. As mainly tested with the DP connector type, I never had any issue. I need to check if calling `drm_edid_connector_update` fails if the EDID property does not exist.

Thanks,
Louis Chauvet

>Ian,
Jani Nikula Nov. 25, 2024, 9:45 a.m. UTC | #3
On Fri, 22 Nov 2024, Louis Chauvet <louis.chauvet@bootlin.com> wrote:
> To properly test the EDID reading without using the DRM override, add an
> option to configure the EDID for a connector.
>
> Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
> ---
>  drivers/gpu/drm/vkms/vkms_config.c |  1 +
>  drivers/gpu/drm/vkms/vkms_config.h |  2 ++
>  drivers/gpu/drm/vkms/vkms_output.c | 37 ++++++++++++++++++++++++++++++++++---
>  3 files changed, 37 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c
> index ac1a9658c5075c118d59da965ca3392355ccb2b2..1a1234d4f10fa8e5ea6bd649139ecc10c991f875 100644
> --- a/drivers/gpu/drm/vkms/vkms_config.c
> +++ b/drivers/gpu/drm/vkms/vkms_config.c
> @@ -199,6 +199,7 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *v
>  	xa_init_flags(&vkms_config_connector->possible_encoders, XA_FLAGS_ALLOC);
>  	vkms_config_connector->type = DRM_MODE_CONNECTOR_VIRTUAL;
>  	vkms_config_connector->status = connector_status_unknown;
> +	vkms_config_connector->edid_blob_len = 0;
>  
>  	return vkms_config_connector;
>  }
> diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h
> index bba56c9d8aeceac97a4339ef42ab663c5dc54e65..1220b16f6c98d1ebb0ae55d662a84fe25e1a6a02 100644
> --- a/drivers/gpu/drm/vkms/vkms_config.h
> +++ b/drivers/gpu/drm/vkms/vkms_config.h
> @@ -112,6 +112,8 @@ struct vkms_config_connector {
>  	struct xarray possible_encoders;
>  	int type;
>  	enum drm_connector_status status;
> +	char edid_blob[PAGE_SIZE];
> +	int edid_blob_len;
>  
>  	/* Internal usage */
>  	struct drm_connector *connector;
> diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c
> index fc6a0cdade0739b94820ed4e0924cf355137fe79..56590afb33d75465971d10a282040690840cdbee 100644
> --- a/drivers/gpu/drm/vkms/vkms_output.c
> +++ b/drivers/gpu/drm/vkms/vkms_output.c
> @@ -31,13 +31,44 @@ static const struct drm_connector_funcs vkms_connector_funcs = {
>  	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
>  };
>  
> +static int vkms_connector_read_block(void *context, u8 *buf, unsigned int block, size_t len)
> +{
> +	struct vkms_config_connector *config = context;
> +
> +	if (block * len + len > config->edid_blob_len)

The parameters to the read block function are a bit weird for historical
reasons. The start offset is indicated by block number, length by
len. The start byte offset is thus block * EDID_LENGTH! There's no
smaller granularity for start offset. However len can be < EDID_LENGTH!

So the above should be (block * EDID_LENGTH + len > edid_blob_len)

> +		return 1;
> +	memcpy(buf, &config->edid_blob[block * len], len);

And this should be &config->edid_blob[block * EDID_LENGTH].

(Your patch would work, but just by coincidence due to the way the read
block function is currently called.)

> +	return 0;
> +}
> +
>  static int vkms_conn_get_modes(struct drm_connector *connector)
>  {
> +	const struct drm_edid *drm_edid = NULL;
>  	int count;
> +	struct vkms_config_connector *connector_cfg;
> +	struct vkms_device *vkmsdev = drm_device_to_vkms_device(connector->dev);
> +	struct vkms_config_connector *context = NULL;
> +
> +	list_for_each_entry(connector_cfg, &vkmsdev->config->connectors, link) {
> +		if (connector_cfg->connector == connector) {
> +			context = connector_cfg;
> +			break;
> +		}
> +	}
> +	if (context)
> +		drm_edid = drm_edid_read_custom(connector, vkms_connector_read_block, context);

Thanks for using drm_edid_read_custom() for this btw!

> +
> +	/*
> +	 * Unconditionally update the connector. If the EDID was read
> +	 * successfully, fill in the connector information derived from the
> +	 * EDID. Otherwise, if the EDID is NULL, clear the connector
> +	 * information.
> +	 */
> +	drm_edid_connector_update(connector, drm_edid);
> +
> +	count = drm_edid_connector_add_modes(connector);
>  
> -	/* Use the default modes list from DRM */
> -	count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
> -	drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);

I don't really know anything about your use case, but don't you want to
fall back to the above for drm_edid == NULL? *shrug*

BR,
Jani.

> +	drm_edid_free(drm_edid);
>  
>  	return count;
>  }
Louis Chauvet Nov. 25, 2024, 10:19 a.m. UTC | #4
Le 25 novembre 2024 09:45:04 UTC, Jani Nikula <jani.nikula@linux.intel.com> a écrit :
>On Fri, 22 Nov 2024, Louis Chauvet <louis.chauvet@bootlin.com> wrote:
>> To properly test the EDID reading without using the DRM override, add an
>> option to configure the EDID for a connector.
>>
>> Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
>> ---
>>  drivers/gpu/drm/vkms/vkms_config.c |  1 +
>>  drivers/gpu/drm/vkms/vkms_config.h |  2 ++
>>  drivers/gpu/drm/vkms/vkms_output.c | 37 ++++++++++++++++++++++++++++++++++---
>>  3 files changed, 37 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c
>> index ac1a9658c5075c118d59da965ca3392355ccb2b2..1a1234d4f10fa8e5ea6bd649139ecc10c991f875 100644
>> --- a/drivers/gpu/drm/vkms/vkms_config.c
>> +++ b/drivers/gpu/drm/vkms/vkms_config.c
>> @@ -199,6 +199,7 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *v
>>  	xa_init_flags(&vkms_config_connector->possible_encoders, XA_FLAGS_ALLOC);
>>  	vkms_config_connector->type = DRM_MODE_CONNECTOR_VIRTUAL;
>>  	vkms_config_connector->status = connector_status_unknown;
>> +	vkms_config_connector->edid_blob_len = 0;
>>  
>>  	return vkms_config_connector;
>>  }
>> diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h
>> index bba56c9d8aeceac97a4339ef42ab663c5dc54e65..1220b16f6c98d1ebb0ae55d662a84fe25e1a6a02 100644
>> --- a/drivers/gpu/drm/vkms/vkms_config.h
>> +++ b/drivers/gpu/drm/vkms/vkms_config.h
>> @@ -112,6 +112,8 @@ struct vkms_config_connector {
>>  	struct xarray possible_encoders;
>>  	int type;
>>  	enum drm_connector_status status;
>> +	char edid_blob[PAGE_SIZE];
>> +	int edid_blob_len;
>>  
>>  	/* Internal usage */
>>  	struct drm_connector *connector;
>> diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c
>> index fc6a0cdade0739b94820ed4e0924cf355137fe79..56590afb33d75465971d10a282040690840cdbee 100644
>> --- a/drivers/gpu/drm/vkms/vkms_output.c
>> +++ b/drivers/gpu/drm/vkms/vkms_output.c
>> @@ -31,13 +31,44 @@ static const struct drm_connector_funcs vkms_connector_funcs = {
>>  	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
>>  };
>>  
>> +static int vkms_connector_read_block(void *context, u8 *buf, unsigned int block, size_t len)
>> +{
>> +	struct vkms_config_connector *config = context;
>> +
>> +	if (block * len + len > config->edid_blob_len)
>
>The parameters to the read block function are a bit weird for historical
>reasons. The start offset is indicated by block number, length by
>len. The start byte offset is thus block * EDID_LENGTH! There's no
>smaller granularity for start offset. However len can be < EDID_LENGTH!
>
>So the above should be (block * EDID_LENGTH + len > edid_blob_len)
>
>> +		return 1;
>> +	memcpy(buf, &config->edid_blob[block * len], len);
>
>And this should be &config->edid_blob[block * EDID_LENGTH].
>
>(Your patch would work, but just by coincidence due to the way the read
>block function is currently called.)

Thanks for those clarifications! 

>> +	return 0;
>> +}
>> +
>>  static int vkms_conn_get_modes(struct drm_connector *connector)
>>  {
>> +	const struct drm_edid *drm_edid = NULL;
>>  	int count;
>> +	struct vkms_config_connector *connector_cfg;
>> +	struct vkms_device *vkmsdev = drm_device_to_vkms_device(connector->dev);
>> +	struct vkms_config_connector *context = NULL;
>> +
>> +	list_for_each_entry(connector_cfg, &vkmsdev->config->connectors, link) {
>> +		if (connector_cfg->connector == connector) {
>> +			context = connector_cfg;
>> +			break;
>> +		}
>> +	}
>> +	if (context)
>> +		drm_edid = drm_edid_read_custom(connector, vkms_connector_read_block, context);
>
>Thanks for using drm_edid_read_custom() for this btw!
>
>> +
>> +	/*
>> +	 * Unconditionally update the connector. If the EDID was read
>> +	 * successfully, fill in the connector information derived from the
>> +	 * EDID. Otherwise, if the EDID is NULL, clear the connector
>> +	 * information.
>> +	 */
>> +	drm_edid_connector_update(connector, drm_edid);
>> +
>> +	count = drm_edid_connector_add_modes(connector);
>>  
>> -	/* Use the default modes list from DRM */
>> -	count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
>> -	drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
>
>I don't really know anything about your use case, but don't you want to
>fall back to the above for drm_edid == NULL? *shrug*

You are right, I will probably fallback to noedid version, at least for VIRTUAL connectors.

Or maybe I will add something in VKMS configuration to use "empty edid", "default modes_noedid" or "custom_edid".

This way you will be able to test all the scenarios for your userspace.

Thanks for your review,
Louis Chauvet

>BR,
>Jani.
>
>> +	drm_edid_free(drm_edid);
>>  
>>  	return count;
>>  }
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c
index ac1a9658c5075c118d59da965ca3392355ccb2b2..1a1234d4f10fa8e5ea6bd649139ecc10c991f875 100644
--- a/drivers/gpu/drm/vkms/vkms_config.c
+++ b/drivers/gpu/drm/vkms/vkms_config.c
@@ -199,6 +199,7 @@  struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *v
 	xa_init_flags(&vkms_config_connector->possible_encoders, XA_FLAGS_ALLOC);
 	vkms_config_connector->type = DRM_MODE_CONNECTOR_VIRTUAL;
 	vkms_config_connector->status = connector_status_unknown;
+	vkms_config_connector->edid_blob_len = 0;
 
 	return vkms_config_connector;
 }
diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h
index bba56c9d8aeceac97a4339ef42ab663c5dc54e65..1220b16f6c98d1ebb0ae55d662a84fe25e1a6a02 100644
--- a/drivers/gpu/drm/vkms/vkms_config.h
+++ b/drivers/gpu/drm/vkms/vkms_config.h
@@ -112,6 +112,8 @@  struct vkms_config_connector {
 	struct xarray possible_encoders;
 	int type;
 	enum drm_connector_status status;
+	char edid_blob[PAGE_SIZE];
+	int edid_blob_len;
 
 	/* Internal usage */
 	struct drm_connector *connector;
diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c
index fc6a0cdade0739b94820ed4e0924cf355137fe79..56590afb33d75465971d10a282040690840cdbee 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -31,13 +31,44 @@  static const struct drm_connector_funcs vkms_connector_funcs = {
 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 };
 
+static int vkms_connector_read_block(void *context, u8 *buf, unsigned int block, size_t len)
+{
+	struct vkms_config_connector *config = context;
+
+	if (block * len + len > config->edid_blob_len)
+		return 1;
+	memcpy(buf, &config->edid_blob[block * len], len);
+	return 0;
+}
+
 static int vkms_conn_get_modes(struct drm_connector *connector)
 {
+	const struct drm_edid *drm_edid = NULL;
 	int count;
+	struct vkms_config_connector *connector_cfg;
+	struct vkms_device *vkmsdev = drm_device_to_vkms_device(connector->dev);
+	struct vkms_config_connector *context = NULL;
+
+	list_for_each_entry(connector_cfg, &vkmsdev->config->connectors, link) {
+		if (connector_cfg->connector == connector) {
+			context = connector_cfg;
+			break;
+		}
+	}
+	if (context)
+		drm_edid = drm_edid_read_custom(connector, vkms_connector_read_block, context);
+
+	/*
+	 * Unconditionally update the connector. If the EDID was read
+	 * successfully, fill in the connector information derived from the
+	 * EDID. Otherwise, if the EDID is NULL, clear the connector
+	 * information.
+	 */
+	drm_edid_connector_update(connector, drm_edid);
+
+	count = drm_edid_connector_add_modes(connector);
 
-	/* Use the default modes list from DRM */
-	count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
-	drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
+	drm_edid_free(drm_edid);
 
 	return count;
 }