From nobody Mon Feb 9 19:26:32 2026 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E04041DDC03 for ; Wed, 29 Jan 2025 11:01:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738148480; cv=none; b=W2wApF8bDc3TGIaV3slhH25T0dqZCg4Cq6Ph2cqVqSBjkAaxD/kX75X9itTrIu5n6nhiMHT5NVx5ud7YgC0X+yK1M2hZJknAxMGLwOfOe9e9t9j5CGgoOw4zCV6RMzbI21iFEmEPAaFZT5Ef6xE6y0rJpsQh3GdA6IuaKU3oYNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738148480; c=relaxed/simple; bh=xt9y9griwrDkz21B79ZRhlUQ54QCkFUACv5p0RVf3LU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GNVnmCdx+Yitu2s18JxA0VliYVf+Yd8AgG8cm7qoBZg2EyarWgka91ULO7Ch0/2r1esSHqHfQYcECTGw+6QVBbXNLbR72pkQBEwfMdtJjAjAT4lhSyMOmfZxyRwgpvzON0s249Vao4t2D7+eJRApKhaP4pBUqN7vrvLQkOSxEkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IoKFoJwE; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IoKFoJwE" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-38a88ba968aso6539010f8f.3 for ; Wed, 29 Jan 2025 03:01:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738148476; x=1738753276; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q88yikrH24hbqKVdPbrR3EWE1tAj+IlW/np5tlv3WjE=; b=IoKFoJwEQ1zj6Gflaal8AABli0RTv+1JQRhURbW3BnMQrxObjQ00If5+zXHL9BBmrm Bz3QQaHpNFhfR9XYC1CNYsU8attvla99J02vZefSGSM1sSUzjuExj/MFGDFTPWPgpGmr 4lNXQXfCgSavGsy+KwlyRQE6rz/unfUP57fV5HUL7v6xuEgXQvVkPNtTel77epzf5m6k lv1BH8TlJzJEnXCmwG+8sueIj8y/EWOek5Xju8ldu50b6haVK4aK8pmBCQGPlD7vcE9O opSZbwG3YK/ie9OcrOVUQiBEuiePXm5PueIKEHhRMJXtxb9mC2xE/IGiFbA5b4d2XJEe /UuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738148476; x=1738753276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q88yikrH24hbqKVdPbrR3EWE1tAj+IlW/np5tlv3WjE=; b=ozRujJwwBpd12wXYw68SrIIKqeNnquh2KeF+WRlPxCkTPXz0jE/h5b9WO8tZMTd0SP cfOk5LT6qI6jTvhKT6NpDbpCNi/TI7YiLrnylxo/OYsB7HK6gPWGxF5MvIu0tGfVP0Hd HeY+gkXNczA7WbxJFA7AXZHxSTkcxGX2Vb4z/u6z+Phl1pFIVtuPal0RmmUGZWn25wIn /e5kvmyLWYLlx8c6Eo2EayP25Q+weLdEfj0VXd507f2eZAlL0Vaz31es3gcPp7p+rWUq siTPs6GQo2uM2YzX1p4XqyaCt8ohen2JCszXBdetID2sSknDMurSluUa1MeP5fWYvfOJ eeSQ== X-Forwarded-Encrypted: i=1; AJvYcCUUK9wOD65QabaR5UbFxDMOqNOZ35fT5J60uKi8BBGrJ7iiqKnVVuDNTNtfnGQwy0k06FFyJWH49FNReqI=@vger.kernel.org X-Gm-Message-State: AOJu0YzGyrax7krKYb0rIgeeUbTDRr/ranfegxHFVuuqlPjphnJpLI6L g3Y6Ce+UMDfssGQAYXbx9M312YyBL3MM+RLddIbO9tVOLRB0OlmN X-Gm-Gg: ASbGncvsD2qnQEEsvnM0XGmws2vB5zT3iVk+GTBnPQcnzICu/l25GEWW8wuXsDs6IOd kGlFWafa0bvmNliIBaOQ6yM2tOU/ZOhOURLH3WfITcwQmE2W2ppT20fzYcWHplIUY/6OdZp6ydO gGRHC05wYUjIaoXGOGpagxhLviP7S+Sq34u+pdK7Q4qUqyRHhRGSxIJKLSdSMQ+OJyl56uyyFzu aD7piAnZv8DQCenXaedCgWM9pHCHzqr/QhMHJGbvAkvv/KObBV5ecJ/poW9CntckZxccrngsMfm a0LV1kZBZlwjwpNm X-Google-Smtp-Source: AGHT+IHDlygoZF3UMYScVhrgVjNYuMwkTq/5UtcpTgAKwbdLoTEd/tYv5i194zzG2JjgIAWcJ9vP7Q== X-Received: by 2002:adf:f943:0:b0:385:f996:1b8e with SMTP id ffacd0b85a97d-38c51951006mr2222645f8f.16.1738148475782; Wed, 29 Jan 2025 03:01:15 -0800 (PST) Received: from fedora.. ([94.73.37.161]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a176434sm16947113f8f.13.2025.01.29.03.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 03:01:15 -0800 (PST) From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= To: louis.chauvet@bootlin.com Cc: hamohammed.sa@gmail.com, simona@ffwll.ch, melissa.srw@gmail.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Subject: [PATCH 09/13] drm/vkms: Allow to attach planes and CRTCs Date: Wed, 29 Jan 2025 12:00:55 +0100 Message-ID: <20250129110059.12199-10-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129110059.12199-1-jose.exposito89@gmail.com> References: <20250129110059.12199-1-jose.exposito89@gmail.com> 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 Add a list of possible CRTCs to the plane configuration and helpers to attach, detach and get the primary and cursor planes attached to a CRTC. Now that the default configuration has its planes and CRTC correctly attached, configure the output following the configuration. Signed-off-by: Louis Chauvet Signed-off-by: Jos=C3=A9 Exp=C3=B3sito --- drivers/gpu/drm/vkms/tests/vkms_config_test.c | 185 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.c | 166 ++++++++++++++-- drivers/gpu/drm/vkms/vkms_config.h | 55 +++++- drivers/gpu/drm/vkms/vkms_output.c | 77 ++++++-- 4 files changed, 446 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/vkms/tests/vkms_config_test.c b/drivers/gpu/dr= m/vkms/tests/vkms_config_test.c index b5907b060a5c..5e698616491a 100644 --- a/drivers/gpu/drm/vkms/tests/vkms_config_test.c +++ b/drivers/gpu/drm/vkms/tests/vkms_config_test.c @@ -87,6 +87,18 @@ static void vkms_config_test_default_config(struct kunit= *test) KUNIT_EXPECT_EQ(test, vkms_config_crtc_get_writeback(crtc_cfg), params->enable_writeback); =20 + list_for_each_entry(plane_cfg, &config->planes, link) { + struct vkms_config_crtc *possible_crtc; + int n_possible_crtcs =3D 0; + unsigned long idx =3D 0; + + xa_for_each(&plane_cfg->possible_crtcs, idx, possible_crtc) { + KUNIT_EXPECT_PTR_EQ(test, crtc_cfg, possible_crtc); + n_possible_crtcs++; + } + KUNIT_EXPECT_EQ(test, n_possible_crtcs, 1); + } + KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config)); =20 vkms_config_destroy(config); @@ -191,6 +203,8 @@ static void vkms_config_test_valid_plane_type(struct ku= nit *test) { struct vkms_config *config; struct vkms_config_plane *plane_cfg; + struct vkms_config_crtc *crtc_cfg; + int err; =20 config =3D vkms_config_default_create(false, false, false); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config); @@ -198,16 +212,26 @@ static void vkms_config_test_valid_plane_type(struct = kunit *test) plane_cfg =3D list_first_entry(&config->planes, typeof(*plane_cfg), link); vkms_config_destroy_plane(plane_cfg); =20 + crtc_cfg =3D list_first_entry(&config->crtcs, typeof(*crtc_cfg), link); + /* Invalid: No primary plane */ plane_cfg =3D vkms_config_add_plane(config); vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_OVERLAY); + err =3D vkms_config_plane_attach_crtc(plane_cfg, crtc_cfg); + KUNIT_EXPECT_EQ(test, err, 0); KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config)); =20 /* Invalid: Multiple primary planes */ plane_cfg =3D vkms_config_add_plane(config); vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_PRIMARY); + err =3D vkms_config_plane_attach_crtc(plane_cfg, crtc_cfg); + KUNIT_EXPECT_EQ(test, err, 0); + plane_cfg =3D vkms_config_add_plane(config); vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_PRIMARY); + err =3D vkms_config_plane_attach_crtc(plane_cfg, crtc_cfg); + KUNIT_EXPECT_EQ(test, err, 0); + KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config)); =20 /* Valid: One primary plane */ @@ -217,14 +241,50 @@ static void vkms_config_test_valid_plane_type(struct = kunit *test) /* Invalid: Multiple cursor planes */ plane_cfg =3D vkms_config_add_plane(config); vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_CURSOR); + err =3D vkms_config_plane_attach_crtc(plane_cfg, crtc_cfg); + KUNIT_EXPECT_EQ(test, err, 0); + plane_cfg =3D vkms_config_add_plane(config); vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_CURSOR); + err =3D vkms_config_plane_attach_crtc(plane_cfg, crtc_cfg); + KUNIT_EXPECT_EQ(test, err, 0); + KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config)); =20 /* Valid: One primary and one cursor plane */ vkms_config_destroy_plane(plane_cfg); KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config)); =20 + /* Invalid: Second CRTC without primary plane */ + crtc_cfg =3D vkms_config_add_crtc(config); + KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config)); + + /* Valid: Second CRTC with a primary plane */ + plane_cfg =3D vkms_config_add_plane(config); + vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_PRIMARY); + err =3D vkms_config_plane_attach_crtc(plane_cfg, crtc_cfg); + KUNIT_EXPECT_EQ(test, err, 0); + KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config)); + + vkms_config_destroy(config); +} + +static void vkms_config_test_valid_plane_possible_crtcs(struct kunit *test) +{ + struct vkms_config *config; + struct vkms_config_plane *plane_cfg; + struct vkms_config_crtc *crtc_cfg; + + config =3D vkms_config_default_create(false, false, false); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config); + + plane_cfg =3D list_first_entry(&config->planes, typeof(*plane_cfg), link); + crtc_cfg =3D list_first_entry(&config->crtcs, typeof(*crtc_cfg), link); + + /* Invalid: Primary plane without a possible CRTC */ + vkms_config_plane_detach_crtc(plane_cfg, crtc_cfg); + KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config)); + vkms_config_destroy(config); } =20 @@ -251,6 +311,128 @@ static void vkms_config_test_valid_crtc_number(struct= kunit *test) vkms_config_destroy(config); } =20 +static void vkms_config_test_plane_attach_crtc(struct kunit *test) +{ + struct vkms_config *config; + struct vkms_config_plane *overlay_cfg; + struct vkms_config_plane *primary_cfg; + struct vkms_config_plane *cursor_cfg; + struct vkms_config_crtc *crtc_cfg; + int err; + + config =3D vkms_config_create("test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config); + + overlay_cfg =3D vkms_config_add_plane(config); + vkms_config_plane_set_type(overlay_cfg, DRM_PLANE_TYPE_OVERLAY); + primary_cfg =3D vkms_config_add_plane(config); + vkms_config_plane_set_type(primary_cfg, DRM_PLANE_TYPE_PRIMARY); + cursor_cfg =3D vkms_config_add_plane(config); + vkms_config_plane_set_type(cursor_cfg, DRM_PLANE_TYPE_CURSOR); + + crtc_cfg =3D vkms_config_add_crtc(config); + + /* No primary or cursor planes */ + KUNIT_EXPECT_NULL(test, vkms_config_crtc_primary_plane(config, crtc_cfg)); + KUNIT_EXPECT_NULL(test, vkms_config_crtc_cursor_plane(config, crtc_cfg)); + + /* Overlay plane, but no primary or cursor planes */ + err =3D vkms_config_plane_attach_crtc(overlay_cfg, crtc_cfg); + KUNIT_EXPECT_EQ(test, err, 0); + KUNIT_EXPECT_NULL(test, vkms_config_crtc_primary_plane(config, crtc_cfg)); + KUNIT_EXPECT_NULL(test, vkms_config_crtc_cursor_plane(config, crtc_cfg)); + + /* Primary plane, attaching it twice must fail */ + err =3D vkms_config_plane_attach_crtc(primary_cfg, crtc_cfg); + KUNIT_EXPECT_EQ(test, err, 0); + err =3D vkms_config_plane_attach_crtc(primary_cfg, crtc_cfg); + KUNIT_EXPECT_NE(test, err, 0); + KUNIT_EXPECT_PTR_EQ(test, + vkms_config_crtc_primary_plane(config, crtc_cfg), + primary_cfg); + KUNIT_EXPECT_NULL(test, vkms_config_crtc_cursor_plane(config, crtc_cfg)); + + /* Primary and cursor planes */ + err =3D vkms_config_plane_attach_crtc(cursor_cfg, crtc_cfg); + KUNIT_EXPECT_EQ(test, err, 0); + KUNIT_EXPECT_PTR_EQ(test, + vkms_config_crtc_primary_plane(config, crtc_cfg), + primary_cfg); + KUNIT_EXPECT_PTR_EQ(test, + vkms_config_crtc_cursor_plane(config, crtc_cfg), + cursor_cfg); + + /* Detach primary and destroy cursor plane */ + vkms_config_plane_detach_crtc(overlay_cfg, crtc_cfg); + vkms_config_plane_detach_crtc(primary_cfg, crtc_cfg); + vkms_config_destroy_plane(cursor_cfg); + KUNIT_EXPECT_NULL(test, vkms_config_crtc_primary_plane(config, crtc_cfg)); + KUNIT_EXPECT_NULL(test, vkms_config_crtc_cursor_plane(config, crtc_cfg)); + + vkms_config_destroy(config); +} + +static void vkms_config_test_plane_get_possible_crtcs(struct kunit *test) +{ + struct vkms_config *config; + struct vkms_config_plane *plane_cfg1, *plane_cfg2; + struct vkms_config_crtc *crtc_cfg1, *crtc_cfg2; + struct vkms_config_crtc **array; + size_t length; + int err; + + config =3D vkms_config_create("test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config); + + plane_cfg1 =3D vkms_config_add_plane(config); + plane_cfg2 =3D vkms_config_add_plane(config); + crtc_cfg1 =3D vkms_config_add_crtc(config); + crtc_cfg2 =3D vkms_config_add_crtc(config); + + /* No possible CRTCs */ + array =3D vkms_config_plane_get_possible_crtcs(plane_cfg1, &length); + KUNIT_ASSERT_EQ(test, length, 0); + KUNIT_ASSERT_NULL(test, array); + + array =3D vkms_config_plane_get_possible_crtcs(plane_cfg2, &length); + KUNIT_ASSERT_EQ(test, length, 0); + KUNIT_ASSERT_NULL(test, array); + + /* Plane 1 attached to CRTC 1 and 2 */ + err =3D vkms_config_plane_attach_crtc(plane_cfg1, crtc_cfg1); + KUNIT_EXPECT_EQ(test, err, 0); + err =3D vkms_config_plane_attach_crtc(plane_cfg1, crtc_cfg2); + KUNIT_EXPECT_EQ(test, err, 0); + + array =3D vkms_config_plane_get_possible_crtcs(plane_cfg1, &length); + KUNIT_ASSERT_EQ(test, length, 2); + KUNIT_ASSERT_PTR_EQ(test, array[0], crtc_cfg1); + KUNIT_ASSERT_PTR_EQ(test, array[1], crtc_cfg2); + kfree(array); + + array =3D vkms_config_plane_get_possible_crtcs(plane_cfg2, &length); + KUNIT_ASSERT_EQ(test, length, 0); + KUNIT_ASSERT_NULL(test, array); + + /* Plane 1 attached to CRTC 1 and plane 2 to CRTC 2 */ + vkms_config_plane_detach_crtc(plane_cfg1, crtc_cfg2); + + array =3D vkms_config_plane_get_possible_crtcs(plane_cfg1, &length); + KUNIT_ASSERT_EQ(test, length, 1); + KUNIT_ASSERT_PTR_EQ(test, array[0], crtc_cfg1); + kfree(array); + + err =3D vkms_config_plane_attach_crtc(plane_cfg2, crtc_cfg2); + KUNIT_EXPECT_EQ(test, err, 0); + + array =3D vkms_config_plane_get_possible_crtcs(plane_cfg2, &length); + KUNIT_ASSERT_EQ(test, length, 1); + KUNIT_ASSERT_PTR_EQ(test, array[0], crtc_cfg2); + kfree(array); + + vkms_config_destroy(config); +} + static struct kunit_case vkms_config_test_cases[] =3D { KUNIT_CASE(vkms_config_test_empty_config), KUNIT_CASE_PARAM(vkms_config_test_default_config, @@ -259,7 +441,10 @@ static struct kunit_case vkms_config_test_cases[] =3D { KUNIT_CASE(vkms_config_test_get_crtcs), KUNIT_CASE(vkms_config_test_valid_plane_number), KUNIT_CASE(vkms_config_test_valid_plane_type), + KUNIT_CASE(vkms_config_test_valid_plane_possible_crtcs), KUNIT_CASE(vkms_config_test_valid_crtc_number), + KUNIT_CASE(vkms_config_test_plane_attach_crtc), + KUNIT_CASE(vkms_config_test_plane_get_possible_crtcs), {} }; =20 diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms= _config.c index 4128892836d7..a2ce4905589b 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -50,13 +50,20 @@ struct vkms_config *vkms_config_default_create(bool ena= ble_cursor, goto err_alloc; vkms_config_crtc_set_writeback(crtc_cfg, enable_writeback); =20 + if (vkms_config_plane_attach_crtc(plane_cfg, crtc_cfg)) + goto err_alloc; + if (enable_overlay) { for (n =3D 0; n < NUM_OVERLAY_PLANES; n++) { plane_cfg =3D vkms_config_add_plane(config); if (IS_ERR(plane_cfg)) goto err_alloc; + vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_OVERLAY); + + if (vkms_config_plane_attach_crtc(plane_cfg, crtc_cfg)) + goto err_alloc; } } =20 @@ -64,7 +71,11 @@ struct vkms_config *vkms_config_default_create(bool enab= le_cursor, plane_cfg =3D vkms_config_add_plane(config); if (IS_ERR(plane_cfg)) goto err_alloc; + vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_CURSOR); + + if (vkms_config_plane_attach_crtc(plane_cfg, crtc_cfg)) + goto err_alloc; } =20 return config; @@ -156,31 +167,39 @@ static bool valid_plane_number(struct vkms_config *co= nfig) return true; } =20 -static bool valid_plane_type(struct vkms_config *config) +static bool valid_plane_type(struct vkms_config *config, + struct vkms_config_crtc *crtc_cfg) { struct vkms_config_plane *plane_cfg; bool has_primary_plane =3D false; bool has_cursor_plane =3D false; =20 list_for_each_entry(plane_cfg, &config->planes, link) { + struct vkms_config_crtc *possible_crtc; + unsigned long idx =3D 0; enum drm_plane_type type; =20 type =3D vkms_config_plane_get_type(plane_cfg); =20 - if (type =3D=3D DRM_PLANE_TYPE_PRIMARY) { - if (has_primary_plane) { - pr_err("Multiple primary planes\n"); - return false; - } + xa_for_each(&plane_cfg->possible_crtcs, idx, possible_crtc) { + if (possible_crtc !=3D crtc_cfg) + continue; =20 - has_primary_plane =3D true; - } else if (type =3D=3D DRM_PLANE_TYPE_CURSOR) { - if (has_cursor_plane) { - pr_err("Multiple cursor planes\n"); - return false; - } + if (type =3D=3D DRM_PLANE_TYPE_PRIMARY) { + if (has_primary_plane) { + pr_err("Multiple primary planes\n"); + return false; + } =20 - has_cursor_plane =3D true; + has_primary_plane =3D true; + } else if (type =3D=3D DRM_PLANE_TYPE_CURSOR) { + if (has_cursor_plane) { + pr_err("Multiple cursor planes\n"); + return false; + } + + has_cursor_plane =3D true; + } } } =20 @@ -192,6 +211,20 @@ static bool valid_plane_type(struct vkms_config *confi= g) return true; } =20 +static bool valid_plane_possible_crtcs(struct vkms_config *config) +{ + struct vkms_config_plane *plane_cfg; + + list_for_each_entry(plane_cfg, &config->planes, link) { + if (xa_empty(&plane_cfg->possible_crtcs)) { + pr_err("All planes must have at least one possible CRTC\n"); + return false; + } + } + + return true; +} + static bool valid_crtc_number(struct vkms_config *config) { size_t n_crtcs; @@ -207,15 +240,22 @@ static bool valid_crtc_number(struct vkms_config *con= fig) =20 bool vkms_config_is_valid(struct vkms_config *config) { + struct vkms_config_crtc *crtc_cfg; + if (!valid_plane_number(config)) return false; =20 if (!valid_crtc_number(config)) return false; =20 - if (!valid_plane_type(config)) + if (!valid_plane_possible_crtcs(config)) return false; =20 + list_for_each_entry(crtc_cfg, &config->crtcs, link) { + if (!valid_plane_type(config, crtc_cfg)) + return false; + } + return true; } =20 @@ -265,6 +305,7 @@ struct vkms_config_plane *vkms_config_add_plane(struct = vkms_config *config) return ERR_PTR(-ENOMEM); =20 vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_OVERLAY); + xa_init_flags(&plane_cfg->possible_crtcs, XA_FLAGS_ALLOC); =20 list_add_tail(&plane_cfg->link, &config->planes); =20 @@ -273,10 +314,69 @@ struct vkms_config_plane *vkms_config_add_plane(struc= t vkms_config *config) =20 void vkms_config_destroy_plane(struct vkms_config_plane *plane_cfg) { + xa_destroy(&plane_cfg->possible_crtcs); list_del(&plane_cfg->link); kfree(plane_cfg); } =20 +int __must_check vkms_config_plane_attach_crtc(struct vkms_config_plane *p= lane_cfg, + struct vkms_config_crtc *crtc_cfg) +{ + struct vkms_config_crtc *possible_crtc; + unsigned long idx =3D 0; + u32 crtc_idx =3D 0; + + xa_for_each(&plane_cfg->possible_crtcs, idx, possible_crtc) { + if (possible_crtc =3D=3D crtc_cfg) + return -EINVAL; + } + + return xa_alloc(&plane_cfg->possible_crtcs, &crtc_idx, crtc_cfg, + xa_limit_32b, GFP_KERNEL); +} + +void vkms_config_plane_detach_crtc(struct vkms_config_plane *plane_cfg, + struct vkms_config_crtc *crtc_cfg) +{ + struct vkms_config_crtc *possible_crtc; + unsigned long idx =3D 0; + + xa_for_each(&plane_cfg->possible_crtcs, idx, possible_crtc) { + if (possible_crtc =3D=3D crtc_cfg) + xa_erase(&plane_cfg->possible_crtcs, idx); + } +} + +struct vkms_config_crtc **vkms_config_plane_get_possible_crtcs(struct vkms= _config_plane *plane_cfg, + size_t *out_length) +{ + struct vkms_config_crtc **array; + struct vkms_config_crtc *possible_crtc; + unsigned long idx; + size_t length =3D 0; + int n =3D 0; + + xa_for_each(&plane_cfg->possible_crtcs, idx, possible_crtc) + length++; + + if (length =3D=3D 0) { + *out_length =3D length; + return NULL; + } + + array =3D kmalloc_array(length, sizeof(*array), GFP_KERNEL); + if (!array) + return ERR_PTR(-ENOMEM); + + xa_for_each(&plane_cfg->possible_crtcs, idx, possible_crtc) { + array[n] =3D possible_crtc; + n++; + } + + *out_length =3D length; + return array; +} + struct vkms_config_crtc *vkms_config_add_crtc(struct vkms_config *config) { struct vkms_config_crtc *crtc_cfg; @@ -295,6 +395,44 @@ struct vkms_config_crtc *vkms_config_add_crtc(struct v= kms_config *config) void vkms_config_destroy_crtc(struct vkms_config *config, struct vkms_config_crtc *crtc_cfg) { + struct vkms_config_plane *plane_cfg; + + list_for_each_entry(plane_cfg, &config->planes, link) + vkms_config_plane_detach_crtc(plane_cfg, crtc_cfg); + list_del(&crtc_cfg->link); kfree(crtc_cfg); } + +static struct vkms_config_plane *vkms_config_crtc_get_plane(const struct v= kms_config *config, + struct vkms_config_crtc *crtc_cfg, + enum drm_plane_type type) +{ + struct vkms_config_plane *plane_cfg; + struct vkms_config_crtc *possible_crtc; + enum drm_plane_type current_type; + unsigned long idx; + + list_for_each_entry(plane_cfg, &config->planes, link) { + current_type =3D vkms_config_plane_get_type(plane_cfg); + + xa_for_each(&plane_cfg->possible_crtcs, idx, possible_crtc) { + if (possible_crtc =3D=3D crtc_cfg && current_type =3D=3D type) + return plane_cfg; + } + } + + return NULL; +} + +struct vkms_config_plane *vkms_config_crtc_primary_plane(const struct vkms= _config *config, + struct vkms_config_crtc *crtc_cfg) +{ + return vkms_config_crtc_get_plane(config, crtc_cfg, DRM_PLANE_TYPE_PRIMAR= Y); +} + +struct vkms_config_plane *vkms_config_crtc_cursor_plane(const struct vkms_= config *config, + struct vkms_config_crtc *crtc_cfg) +{ + return vkms_config_crtc_get_plane(config, crtc_cfg, DRM_PLANE_TYPE_CURSOR= ); +} diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms= _config.h index a7828fe0c4b2..1f2e6c485d08 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -12,14 +12,12 @@ * struct vkms_config - General configuration for VKMS driver * * @dev_name: Name of the device - * @writeback: If true, a writeback buffer can be attached to the CRTC * @planes: List of planes configured for the device * @crtcs: List of CRTCs configured for the device * @dev: Used to store the current VKMS device. Only set when the device i= s instantiated. */ struct vkms_config { const char *dev_name; - bool writeback; struct list_head planes; struct list_head crtcs; struct vkms_device *dev; @@ -31,6 +29,7 @@ struct vkms_config { * @link: Link to the others planes in vkms_config * @type: Type of the plane. The creator of configuration needs to ensures= that * at least one primary plane is present. + * @possible_crtcs: Array of CRTCs that can be used with this plane * @plane: Internal usage. This pointer should never be considered as vali= d. * It can be used to store a temporary reference to a VKMS plane d= uring * device creation. This pointer is not managed by the configurati= on and @@ -40,6 +39,7 @@ struct vkms_config_plane { struct list_head link; =20 enum drm_plane_type type; + struct xarray possible_crtcs; =20 /* Internal usage */ struct vkms_plane *plane; @@ -194,6 +194,35 @@ vkms_config_plane_set_type(struct vkms_config_plane *p= lane_cfg, plane_cfg->type =3D type; } =20 +/** + * vkms_config_plane_attach_crtc - Attach a plane to a CRTC + * @plane_cfg: Plane to attach + * @crtc_cfg: CRTC to attach @plane_cfg to + */ +int __must_check vkms_config_plane_attach_crtc(struct vkms_config_plane *p= lane_cfg, + struct vkms_config_crtc *crtc_cfg); + +/** + * vkms_config_plane_attach_crtc - Detach a plane from a CRTC + * @plane_cfg: Plane to detach + * @crtc_cfg: CRTC to detach @plane_cfg from + */ +void vkms_config_plane_detach_crtc(struct vkms_config_plane *plane_cfg, + struct vkms_config_crtc *crtc_cfg); + +/** + * vkms_config_plane_get_possible_crtcs() - Return the array of possible C= RTCs + * @plane_cfg: Plane to get the possible CRTCs from + * @out_length: Length of the returned array + * + * Returns: + * A list of pointers to the configurations. On success, the caller is + * responsible to free the returned array, but not its contents. On error, + * it returns an error and @out_length is invalid. + */ +struct vkms_config_crtc **vkms_config_plane_get_possible_crtcs(struct vkms= _config_plane *plane_cfg, + size_t *out_length); + /** * vkms_config_add_crtc() - Add a new CRTC configuration * @config: Configuration to add the CRTC to @@ -234,4 +263,26 @@ vkms_config_crtc_set_writeback(struct vkms_config_crtc= *crtc_cfg, crtc_cfg->writeback =3D writeback; } =20 +/** + * vkms_config_crtc_primary_plane() - Return the primary plane for a CRTC + * @config: Configuration containing the CRTC + * @crtc_config: Target CRTC + * + * Returns: + * The primary plane or NULL if none is assigned yet. + */ +struct vkms_config_plane *vkms_config_crtc_primary_plane(const struct vkms= _config *config, + struct vkms_config_crtc *crtc_cfg); + +/** + * vkms_config_crtc_cursor_plane() - Return the cursor plane for a CRTC + * @config: Configuration containing the CRTC + * @crtc_config: Target CRTC + * + * Returns: + * The cursor plane or NULL if none is assigned yet. + */ +struct vkms_config_plane *vkms_config_crtc_cursor_plane(const struct vkms_= config *config, + struct vkms_config_crtc *crtc_cfg); + #endif /* _VKMS_CONFIG_H_ */ diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms= _output.c index b2ae269e5827..427d0aad8901 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -10,18 +10,24 @@ int vkms_output_init(struct vkms_device *vkmsdev) struct drm_device *dev =3D &vkmsdev->drm; struct vkms_connector *connector; struct drm_encoder *encoder; - struct vkms_output *output; - struct vkms_plane *primary =3D NULL, *cursor =3D NULL; struct vkms_config_plane **plane_cfgs =3D NULL; size_t n_planes; + struct vkms_config_crtc **crtc_cfgs =3D NULL; + size_t n_crtcs; int ret =3D 0; int writeback; - unsigned int n; + unsigned int n, i; =20 plane_cfgs =3D vkms_config_get_planes(vkmsdev->config, &n_planes); if (IS_ERR(plane_cfgs)) return PTR_ERR(plane_cfgs); =20 + crtc_cfgs =3D vkms_config_get_crtcs(vkmsdev->config, &n_crtcs); + if (IS_ERR(crtc_cfgs)) { + ret =3D PTR_ERR(crtc_cfgs); + goto err_free; + } + for (n =3D 0; n < n_planes; n++) { struct vkms_config_plane *plane_cfg; enum drm_plane_type type; @@ -35,19 +41,54 @@ int vkms_output_init(struct vkms_device *vkmsdev) ret =3D PTR_ERR(plane_cfg->plane); goto err_free; } + } + + for (n =3D 0; n < n_crtcs; n++) { + struct vkms_config_crtc *crtc_cfg; + struct vkms_config_plane *primary, *cursor; + + crtc_cfg =3D crtc_cfgs[n]; + primary =3D vkms_config_crtc_primary_plane(vkmsdev->config, crtc_cfg); + cursor =3D vkms_config_crtc_cursor_plane(vkmsdev->config, crtc_cfg); + + crtc_cfg->crtc =3D vkms_crtc_init(dev, &primary->plane->base, + cursor ? &cursor->plane->base : NULL); + if (IS_ERR(crtc_cfg->crtc)) { + DRM_ERROR("Failed to allocate CRTC\n"); + ret =3D PTR_ERR(crtc_cfg->crtc); + goto err_free; + } =20 - if (type =3D=3D DRM_PLANE_TYPE_PRIMARY) - primary =3D plane_cfg->plane; - else if (type =3D=3D DRM_PLANE_TYPE_CURSOR) - cursor =3D plane_cfg->plane; + /* Initialize the writeback component */ + if (vkms_config_crtc_get_writeback(crtc_cfg)) { + writeback =3D vkms_enable_writeback_connector(vkmsdev, crtc_cfg->crtc); + if (writeback) + DRM_ERROR("Failed to init writeback connector\n"); + } } =20 - output =3D vkms_crtc_init(dev, &primary->base, - cursor ? &cursor->base : NULL); - if (IS_ERR(output)) { - DRM_ERROR("Failed to allocate CRTC\n"); - ret =3D PTR_ERR(output); - goto err_free; + for (n =3D 0; n < n_planes; n++) { + struct vkms_config_plane *plane_cfg; + struct vkms_config_crtc **possible_crtcs; + size_t n_possible_crtcs; + + plane_cfg =3D plane_cfgs[n]; + possible_crtcs =3D vkms_config_plane_get_possible_crtcs(plane_cfg, + &n_possible_crtcs); + if (IS_ERR(possible_crtcs)) { + ret =3D PTR_ERR(possible_crtcs); + goto err_free; + } + + for (i =3D 0; i < n_possible_crtcs; i++) { + struct vkms_config_crtc *possible_crtc; + + possible_crtc =3D possible_crtcs[i]; + plane_cfg->plane->base.possible_crtcs |=3D + drm_crtc_mask(&possible_crtc->crtc->crtc); + } + + kfree(possible_crtcs); } =20 connector =3D vkms_connector_init(vkmsdev); @@ -69,7 +110,7 @@ int vkms_output_init(struct vkms_device *vkmsdev) DRM_ERROR("Failed to init encoder\n"); goto err_free; } - encoder->possible_crtcs =3D drm_crtc_mask(&output->crtc); + encoder->possible_crtcs =3D drm_crtc_mask(&crtc_cfgs[0]->crtc->crtc); =20 /* Attach the encoder and the connector */ ret =3D drm_connector_attach_encoder(&connector->base, encoder); @@ -78,17 +119,11 @@ int vkms_output_init(struct vkms_device *vkmsdev) goto err_free; } =20 - /* Initialize the writeback component */ - if (vkmsdev->config->writeback) { - writeback =3D vkms_enable_writeback_connector(vkmsdev, output); - if (writeback) - DRM_ERROR("Failed to init writeback connector\n"); - } - drm_mode_config_reset(dev); =20 err_free: kfree(plane_cfgs); + kfree(crtc_cfgs); =20 return ret; } --=20 2.48.1