From nobody Thu Dec 18 05:13:08 2025 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93A44199FCE for ; Thu, 10 Oct 2024 17:35:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.178.240 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728581731; cv=none; b=J8jbQlZHAqun5rg9x743U9fpZanO2yFhMpT71tZ30sXWidfq5LDbQJydz29dSNGol4wqMiMx+QjxBb0wLnir0ZW3nCNxhxX5NNYAzCQLxrSWmP6rXDuhvQ8G0BMoaoxEjAFYzC78hUSJwpNafeup4SnRXZ4d6EmeoaFg9o2uTTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728581731; c=relaxed/simple; bh=C3nvDo4V6bCHXXVshrM6mSReoIZPTcAhgOpDmwGhhxc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=aR2h3HlaQDdH2PEhrJqeRMBo4ifdAvz22fBjCQtUTcEBTIKtIe2fHl8RW2iSV4OIv7cENbUG1YFJdYnp/hFazWHeyy2KhjBNsIrVTtbqXiWp3B6/xcA6zyT1ks/g9EzYQK7zvVTMa5DnIE2HAUJgqfQBqs1cUkHtZG5SVmncW54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=YiNwHkJ7; arc=none smtp.client-ip=217.70.178.240 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="YiNwHkJ7" Received: from relay7-d.mail.gandi.net (unknown [217.70.183.200]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 16282C08E5 for ; Thu, 10 Oct 2024 17:27:11 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 27EA120002; Thu, 10 Oct 2024 17:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1728581224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cjW1iqTnZt7Tql22SF2gqUtFnIpZXxwf+7g9zNxGy38=; b=YiNwHkJ7tRq5iBMzl0N7JPkJfzUna1pFa89s4mQrxVQH7TzwpVafBwMd3ltOJXx+z+Ds5k b76FfcflT5FzN1MhuZVEXnQm05BhDbxKSNRRFRDfqW25dC46oAxT//xTiD79TGZ1tKHT2n 7xKBpCgZgZuQyxEB3j5KeII39B6Mxflb/7ljiSGilSla7gXbQtZ1bPcnvoL8s+hneAhA+Y kIohXC6HnW4JcspwFeQsS8SL8xk//+ucfQYSoaPjqskjLjPhgGujPqhHplJMVsz0SRIEGR 7HIwknQOrpvJomO/nVbSJvwZOFQ3kIobHqwXo9SpP++bQeIlzeQ9Di/4hqa+tw== From: Louis Chauvet Date: Thu, 10 Oct 2024 19:27:00 +0200 Subject: [PATCH v2] drm/vkms: Remove index parameter from init_vkms_output Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241010-vkms-remove-index-v2-1-6b8d6cfd5a15@bootlin.com> X-B4-Tracking: v=1; b=H4sIAGQOCGcC/32OwQ6CMAyGX4X0bHUMYtST72E4wFak0W26zQVDe HcnxKu3fm2+v/8EgTxTgFMxgafEgZ3NIDcFqKG1V0LWmUEKWYuj2GO6mYCejEv5ZDWNWLV7ErW qDiQkZO/hqedxybw0K3t6vnJ0XJfQtYFQOWM4ngrtDRoOavcb0NIY4WsOHKLz76VcKhf1T49UY omV6knrg1Kd7M+dc/HOdptfQTPP8wcmb4oc7gAAAA== To: Rodrigo Siqueira , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: thomas.petazzoni@bootlin.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Louis Chauvet X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=7390; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=C3nvDo4V6bCHXXVshrM6mSReoIZPTcAhgOpDmwGhhxc=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnCA5m/wReDMSQxhI98iajU4eQYt445jMbcPvw3 NTzr1pzKaWJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZwgOZgAKCRAgrS7GWxAs 4rpDEADAsofiRONRJ7NVdbBpbx5L/WRTUZxrhUkT7wsVM6IwXeKKjLFMM7aT2JwtO7uQDRuhYeq msJC0xa9/7UnTj/yAYnND1H14uQMP38+BPx84sbtjgl3fFE8AaSjrgBQa8lyckzd9klrQ+qyCqH HJVP6JGmBbIuxp9CiVRcuJ7LOEjBpJaQIlxJHiZfmwq/lOO+4L8r+bYsIfhnvBpmt1ibTK8QGNv afuSKs7HNcW1U3/Me6EgqHfJvtKLm3QN7Y7dDkbLjkWmtWaf5u2LzuHoVuNXwep9CJ1AWoMBErG paTkxMdQ4/ELc72qPkMkdgjlYt+cmrZZwdw1Er+Z1pbRwnnoHQJBEY8cI7x16KSiGcWSVHGZyT+ 7ou7MiELsjBvQ/qDDega/4F5a8WnIVwLkpqT+JIGGgRBFh76ZRwXTOof85eVzvn6xVhQFNat3VG B9JRQpY0o6SodExKQNm3/vTce4HN6Mxu051gxGczA6OkvUG/kodxWGtmzbVhuKcukWZLKRHWEMn P8jvn7mRClup6ibxkHOyOSYiCewG0jQonkczY1rAVMmrKB/xjO+ydOS+H05L8HXNIfAvJipSdSk 4GpxptQ2kCbUqIcJhoi3eZM99jI7Ftk4//EV3H2mqKsngG30lgu8oNelfgBk/7Q04o1zcgwp+it IQI9zC6EjAlTzCw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com VKMS currently supports only one CRTC, so it make no sense to have this index configurable. To avoid issues, replace this hardcoded index by drm_crtc_mask when applicable. There is no need to manually set a crtc mask on primary and cursor plane as it is automatically set by drmm_crtc_alloc_with_planes. In addition, this will remove the use of an uninitialized structure in vkms_add_overlay_plane. This currently works by chance because two things: - vkms_plane_init always set a possible_crtcs value, so the problematic branch is never used; - drm_crtc_mask on an kzalloc'd drm_crtc returns BIT(0), and the VKMS CRTC always have this id. Signed-off-by: Louis Chauvet --- Changes in v2: - Applied comments from Jos=C3=A9 - Link to v1: https://lore.kernel.org/r/20240906-vkms-remove-index-v1-1-3cf= edd8ccb2f@bootlin.com --- drivers/gpu/drm/vkms/vkms_drv.c | 2 +- drivers/gpu/drm/vkms/vkms_drv.h | 8 ++---- drivers/gpu/drm/vkms/vkms_output.c | 54 ++++++++++++++--------------------= ---- drivers/gpu/drm/vkms/vkms_plane.c | 4 +-- 4 files changed, 24 insertions(+), 44 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_dr= v.c index 2d1e95cb66e5..0f6805b9fe7b 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -174,7 +174,7 @@ static int vkms_modeset_init(struct vkms_device *vkmsde= v) dev->mode_config.preferred_depth =3D 0; dev->mode_config.helper_private =3D &vkms_mode_config_helpers; =20 - return vkms_output_init(vkmsdev, 0); + return vkms_output_init(vkmsdev); } =20 static int vkms_create(struct vkms_config *config) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_dr= v.h index 672fe191e239..036101ee4ea1 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -212,21 +212,17 @@ int vkms_crtc_init(struct drm_device *dev, struct drm= _crtc *crtc, * vkms_output_init() - Initialize all sub-components needed for a VKMS de= vice. * * @vkmsdev: VKMS device to initialize - * @index: CRTC which can be attached to the planes. The caller must ensur= e that - * @index is positive and less or equals to 31. */ -int vkms_output_init(struct vkms_device *vkmsdev, int index); +int vkms_output_init(struct vkms_device *vkmsdev); =20 /** * vkms_plane_init() - Initialize a plane * * @vkmsdev: VKMS device containing the plane * @type: type of plane to initialize - * @index: CRTC which can be attached to the plane. The caller must ensure= that - * @index is positive and less or equals to 31. */ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, - enum drm_plane_type type, int index); + enum drm_plane_type type); =20 /* CRC Support */ const char *const *vkms_get_crc_sources(struct drm_crtc *crtc, diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms= _output.c index 0a5a185aa0b0..5128aa3b2eb6 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -32,29 +32,14 @@ static const struct drm_connector_helper_funcs vkms_con= n_helper_funcs =3D { .get_modes =3D vkms_conn_get_modes, }; =20 -static int vkms_add_overlay_plane(struct vkms_device *vkmsdev, int index, - struct drm_crtc *crtc) -{ - struct vkms_plane *overlay; - - overlay =3D vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_OVERLAY, index); - if (IS_ERR(overlay)) - return PTR_ERR(overlay); - - if (!overlay->base.possible_crtcs) - overlay->base.possible_crtcs =3D drm_crtc_mask(crtc); - - return 0; -} - -int vkms_output_init(struct vkms_device *vkmsdev, int index) +int vkms_output_init(struct vkms_device *vkmsdev) { struct vkms_output *output =3D &vkmsdev->output; struct drm_device *dev =3D &vkmsdev->drm; struct drm_connector *connector =3D &output->connector; struct drm_encoder *encoder =3D &output->encoder; struct drm_crtc *crtc =3D &output->crtc; - struct vkms_plane *primary, *cursor =3D NULL; + struct vkms_plane *primary, *overlay, *cursor =3D NULL; int ret; int writeback; unsigned int n; @@ -65,34 +50,37 @@ int vkms_output_init(struct vkms_device *vkmsdev, int i= ndex) * The overlay and cursor planes are not mandatory, but can be used to pe= rform complex * composition. */ - primary =3D vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index); + primary =3D vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY); if (IS_ERR(primary)) return PTR_ERR(primary); =20 - if (vkmsdev->config->overlay) { - for (n =3D 0; n < NUM_OVERLAY_PLANES; n++) { - ret =3D vkms_add_overlay_plane(vkmsdev, index, crtc); - if (ret) - return ret; - } - } - if (vkmsdev->config->cursor) { - cursor =3D vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index); + cursor =3D vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR); if (IS_ERR(cursor)) return PTR_ERR(cursor); } =20 - /* [1]: Allocation of a CRTC, its index will be BIT(0) =3D 1 */ ret =3D vkms_crtc_init(dev, crtc, &primary->base, &cursor->base); if (ret) return ret; =20 + if (vkmsdev->config->overlay) { + for (n =3D 0; n < NUM_OVERLAY_PLANES; n++) { + overlay =3D vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_OVERLAY); + if (IS_ERR(overlay)) { + DRM_DEV_ERROR(dev->dev, "Failed to init vkms plane\n"); + ret =3D PTR_ERR(overlay); + goto err_crtc; + } + overlay->base.possible_crtcs =3D drm_crtc_mask(crtc); + } + } + ret =3D drm_connector_init(dev, connector, &vkms_connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL); if (ret) { DRM_ERROR("Failed to init connector\n"); - goto err_connector; + goto err_crtc; } =20 drm_connector_helper_add(connector, &vkms_conn_helper_funcs); @@ -103,11 +91,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int i= ndex) DRM_ERROR("Failed to init encoder\n"); goto err_encoder; } - /* - * This is a hardcoded value to select crtc for the encoder. - * BIT(0) here designate the first registered CRTC, the one allocated in = [1] - */ - encoder->possible_crtcs =3D BIT(0); + encoder->possible_crtcs =3D drm_crtc_mask(crtc); =20 ret =3D drm_connector_attach_encoder(connector, encoder); if (ret) { @@ -131,7 +115,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int i= ndex) err_encoder: drm_connector_cleanup(connector); =20 -err_connector: +err_crtc: drm_crtc_cleanup(crtc); =20 return ret; diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index e5c625ab8e3e..ad137c9a75f5 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -198,12 +198,12 @@ static const struct drm_plane_helper_funcs vkms_plane= _helper_funcs =3D { }; =20 struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, - enum drm_plane_type type, int index) + enum drm_plane_type type) { struct drm_device *dev =3D &vkmsdev->drm; struct vkms_plane *plane; =20 - plane =3D drmm_universal_plane_alloc(dev, struct vkms_plane, base, 1 << i= ndex, + plane =3D drmm_universal_plane_alloc(dev, struct vkms_plane, base, 0, &vkms_plane_funcs, vkms_formats, ARRAY_SIZE(vkms_formats), NULL, type, NULL); --- base-commit: 33c255312660653cf54f8019896b5dca28e3c580 change-id: 20240906-vkms-remove-index-3a6e04c38e02 Best regards, --=20 Louis Chauvet