From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sender5-op-o11.zoho.com (sender5-op-o11.zoho.com [165.173.182.11]) (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 4FC8537E30C for ; Wed, 7 Oct 2026 23:44:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=165.173.182.11 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791416648; cv=pass; b=R5cey6vgMp2e/5u29JjmHH+L3DoxuzKGNYbYElbjeEeclBygkx5ulvQxWlZsFFmG0dSnu38jOr6rIXssnTR8R6k0gHxeYorgxENtoDh2g5i5Dj4ISFfhyYW4WWfsZcu6OCGPjKv+eWgoodR4Lb/osUB2QB7WH6OH9RuEKAFz9HE= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791416648; c=relaxed/simple; bh=TKS1VMi/ENIozBAAIS1XQk/O4kpZWZckYDq6EZfq+aY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bLboTtNBaEATzAneawwXV4asJFXtZX4+4DZrbzx+EYUHO8B7cErxosE4Y4p9QUbAXCAJGweoH5+LZ6yFG8n58XNSNrSdBh9DGIU7EcwnLRUNpIsvsaEm1tRz6b+U68zbjBj5VR3LxCAQCmyrJbXtqfEArxOP0J8WTjWTXNMrBbE= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b=Siuihn6p; arc=pass smtp.client-ip=165.173.182.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b="Siuihn6p" ARC-Seal: i=1; a=rsa-sha256; t=1791416628; cv=none; d=zohomail.com; s=zohoarc; b=NFmvd2bNsA1eDIpr9KUubGeUEzIbprAop9UN3bZ49R91EZ2j282L8VK+j9Mv0da1oT/Jyn49H0AGe/QEy5TOGHmpoYHhT0Un72n5Y/jFQA+eOPRknQvEYM4bBQEfz+OJv30SdAZOmqmGH7fSTAE8tOrNdybhVGNH1wxTnFCYwwQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791416628; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=PxCrfEjByjxWS1pJbCIBaLh3XBE10IgHNoQKH7QJi3Q=; b=BGHvMPmJohGImsE4zi9Z8vksL4eqeRSg1+HWhNXLhCNjI8doXUtSeskr4zknuwltTThdWtKxvCTv3O6k5yVP2udT9skR2e2p+UyRbDRWHPzojWErqtmel1GyCvTyx1/qMY9EqInl2Vqyrr92rxwoegBSGqsk57uWovFAjcKkUPM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=adrian.larumbe@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791416628; s=zohomail; d=collabora.com; i=adrian.larumbe@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=PxCrfEjByjxWS1pJbCIBaLh3XBE10IgHNoQKH7QJi3Q=; b=Siuihn6pH28HsXGLT83Mvpy+kiM9R6bnlzqefaVehogR0qayhKyzxu5lLHPkTmGg Cc22VQj0nWprhbwWTkclLCOcEjVZGFrpFjQhOXxv03oiC+aJ75YjKUfVBtihzc3TM8q dFfq36juiCrQJsX0eOBjrhsz3+Wb83bepgTkzxEU= Received: by smtp.zohomail.com with SMTPS id 1791416626607732.2827269941833; Wed, 7 Oct 2026 16:43:46 -0700 (PDT) From: =?utf-8?q?Adri=C3=A1n_Larumbe?= Date: Thu, 08 Oct 2026 00:42:51 +0100 Subject: [PATCH v13 08/15] drm/panfrost: Move all DRM device initialisation into device_init() 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: 8bit Message-Id: <20261008-claude-fixes-v13-8-d6a493185860@collabora.com> References: <20261008-claude-fixes-v13-0-d6a493185860@collabora.com> In-Reply-To: <20261008-claude-fixes-v13-0-d6a493185860@collabora.com> To: Boris Brezillon , Rob Herring , Steven Price , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Faith Ekstrand , "Marty E. Plummer" , Tomeu Vizoso , Eric Anholt , Robin Murphy , Philipp Zabel Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Collabora Kernel Team , =?utf-8?q?Adri=C3=A1n_Larumbe?= , Neil Armstrong X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6345; i=adrian.larumbe@collabora.com; h=from:subject:message-id; bh=TKS1VMi/ENIozBAAIS1XQk/O4kpZWZckYDq6EZfq+aY=; b=owEB7QES/pANAwAKAQ4mfkzuU0M9AcsmYgBqxtj74Xcnj8q6Hh5mnfbfwNqP+zo2aNeBShIbZ tUxThSn1ZGJAbMEAAEKAB0WIQQyQDDowAUXXfk3B6QOJn5M7lNDPQUCasbY+wAKCRAOJn5M7lND PfVuC/wOOG11imPPqmoB1AM0UrMTO6TXa76i0h6/5T5RCtsbyeSTiQyvOruuZRz2Q/OC90YQOZo 0azBHclVcO4vYgrLg0o0vptTHgBQI/d1dIyKHcGLoPV47Rd3nA3Nic73wpcaWopriyWOEdSKLMh Yz/QyG4A6Zp1oIWpTNleuhd7J5BjnXKiunZmaqxlinkg+VgvRrLIRJS3Y0+8Dmatt3lRBn51v6O RMFRBSAtth8ONB/ctvU8k9I9jGNTJCOnqU+FYkaT1m+paovBkZJMzqfLwYyFmaZ2MgdUmIJ1Nn6 i8zu/y2MT8dgKRj4i5NOSOB5qvR0MA/RIksRERQT/ulnVJpvISJ1uPtiAOXs0GBETEAfLbCHiKb miV3vHvUy/sn3teVUZ1iGlsl4HvTTwoHbcSY7rmDaebOmJGXojMvEKlqgyl9EzkpLQLTGMqPt0T iJrZF6zuRgJs1gufoZBPJtTglGMXy26F0w0XuLynp6o0HlI7HqLJHvd4efHqQ8TpS3Jbg= X-Developer-Key: i=adrian.larumbe@collabora.com; a=openpgp; fpr=324030E8C005175DF93707A40E267E4CEE53433D Ideally the probe() function will do as little as possible, and all device initialisation and registration should happen inside the panfrost device subsystem, just like it's done in Panthor. This also simplifies resource unwinding in the error path. Do the same thing for DRM driver remove, as in, sweep most of the action into panfrost_device_fini(), just like we did for device probe. Reviewed-by: Boris Brezillon Reviewed-by: Steven Price Signed-off-by: Adrián Larumbe --- drivers/gpu/drm/panfrost/panfrost_device.c | 49 ++++++++++++++++++++++++++++ drivers/gpu/drm/panfrost/panfrost_drv.c | 52 +----------------------------- 2 files changed, 50 insertions(+), 51 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_device.c b/drivers/gpu/drm/panfrost/panfrost_device.c index 50f4713bfcfd..a6deabb39fd2 100644 --- a/drivers/gpu/drm/panfrost/panfrost_device.c +++ b/drivers/gpu/drm/panfrost/panfrost_device.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "panfrost_device.h" #include "panfrost_devfreq.h" @@ -256,8 +257,15 @@ static int panfrost_pm_domain_init(struct panfrost_device *pfdev) int panfrost_device_init(struct panfrost_device *pfdev) { + bool device_initialised = false; int err; + pfdev->comp = of_device_get_match_data(pfdev->base.dev); + if (!pfdev->comp) + return -ENODEV; + + pfdev->coherent = device_get_dma_attr(pfdev->base.dev) == DEV_DMA_COHERENT; + #ifdef CONFIG_DEBUG_FS mutex_init(&pfdev->debugfs.gems_lock); INIT_LIST_HEAD(&pfdev->debugfs.gems_list); @@ -319,8 +327,35 @@ int panfrost_device_init(struct panfrost_device *pfdev) if (err) goto out_perfcnt; + device_initialised = true; + + /* The reason we must manually set the PM status and usage counter is + * we have just powered the device up but did not go through the PM + * runtime resume callback, so we need to update these ourselves. + */ + pm_runtime_get_noresume(pfdev->base.dev); + pm_runtime_set_active(pfdev->base.dev); + pm_runtime_mark_last_busy(pfdev->base.dev); + pm_runtime_enable(pfdev->base.dev); + pm_runtime_set_autosuspend_delay(pfdev->base.dev, 50); /* ~3 frames */ + pm_runtime_use_autosuspend(pfdev->base.dev); + + /* + * Register the DRM device with the core and the connectors with + * sysfs + */ + err = drm_dev_register(&pfdev->base, 0); + if (err < 0) + goto err_disable_rpm; + + pm_runtime_put_autosuspend(pfdev->base.dev); + return 0; +err_disable_rpm: + pm_runtime_dont_use_autosuspend(pfdev->base.dev); + pm_runtime_disable(pfdev->base.dev); + panfrost_gem_fini(pfdev); out_perfcnt: panfrost_perfcnt_fini(pfdev); out_job: @@ -339,11 +374,22 @@ int panfrost_device_init(struct panfrost_device *pfdev) panfrost_reset_fini(pfdev); out_pm_domain: panfrost_pm_domain_fini(pfdev); + + if (device_initialised) { + pm_runtime_set_suspended(pfdev->base.dev); + pm_runtime_put_noidle(pfdev->base.dev); + } + return err; } void panfrost_device_fini(struct panfrost_device *pfdev) { + pm_runtime_get_sync(pfdev->base.dev); + + pm_runtime_dont_use_autosuspend(pfdev->base.dev); + pm_runtime_disable(pfdev->base.dev); + panfrost_gem_fini(pfdev); panfrost_perfcnt_fini(pfdev); panfrost_jm_fini(pfdev); @@ -354,6 +400,9 @@ void panfrost_device_fini(struct panfrost_device *pfdev) panfrost_clk_fini(pfdev); panfrost_reset_fini(pfdev); panfrost_pm_domain_fini(pfdev); + + pm_runtime_set_suspended(pfdev->base.dev); + pm_runtime_put_noidle(pfdev->base.dev); } #define PANFROST_EXCEPTION(id) \ diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index 907d4a14a0b5..f77780c72a1a 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -830,7 +830,6 @@ static const struct drm_driver panfrost_drm_driver = { static int panfrost_probe(struct platform_device *pdev) { struct panfrost_device *pfdev; - int err; pfdev = devm_drm_dev_alloc(&pdev->dev, &panfrost_drm_driver, struct panfrost_device, base); @@ -839,50 +838,7 @@ static int panfrost_probe(struct platform_device *pdev) platform_set_drvdata(pdev, pfdev); - pfdev->comp = of_device_get_match_data(&pdev->dev); - if (!pfdev->comp) - return -ENODEV; - - pfdev->coherent = device_get_dma_attr(&pdev->dev) == DEV_DMA_COHERENT; - - err = panfrost_device_init(pfdev); - if (err) { - if (err != -EPROBE_DEFER) - dev_err(&pdev->dev, "Fatal error during GPU init\n"); - goto err_out0; - } - - /* The reason we must manually set the PM status and usage counter is - * we have just powered the device up but did not go through the PM - * runtime resume callback, so we need to update these ourselves. - */ - pm_runtime_get_noresume(pfdev->base.dev); - pm_runtime_set_active(pfdev->base.dev); - pm_runtime_mark_last_busy(pfdev->base.dev); - pm_runtime_enable(pfdev->base.dev); - pm_runtime_set_autosuspend_delay(pfdev->base.dev, 50); /* ~3 frames */ - pm_runtime_use_autosuspend(pfdev->base.dev); - - /* - * Register the DRM device with the core and the connectors with - * sysfs - */ - err = drm_dev_register(&pfdev->base, 0); - if (err < 0) - goto err_out1; - - pm_runtime_put_autosuspend(pfdev->base.dev); - - return 0; - -err_out1: - pm_runtime_dont_use_autosuspend(pfdev->base.dev); - pm_runtime_disable(pfdev->base.dev); - panfrost_device_fini(pfdev); - pm_runtime_set_suspended(pfdev->base.dev); - pm_runtime_put_noidle(pfdev->base.dev); -err_out0: - return err; + return panfrost_device_init(pfdev); } static void panfrost_remove(struct platform_device *pdev) @@ -891,13 +847,7 @@ static void panfrost_remove(struct platform_device *pdev) drm_dev_unregister(&pfdev->base); - pm_runtime_get_sync(pfdev->base.dev); - pm_runtime_dont_use_autosuspend(pfdev->base.dev); - pm_runtime_disable(pfdev->base.dev); panfrost_device_fini(pfdev); - pm_runtime_set_suspended(pfdev->base.dev); - pm_runtime_put_noidle(pfdev->base.dev); - } static ssize_t profiling_show(struct device *dev, -- 2.55.0