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 680CB4D9F7B for ; Fri, 9 Oct 2026 12:35:17 +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=1791549324; cv=pass; b=I3G3a+lH85VgBAPG3yftGvfRInxGAmstVc7hmD4ZlOqXn+z4CH9Q/nf237QQ1tUshWS6LVQWcSCiWB608+Lk2gT+j1zRVEp0xU4+o4v49FztmbJdGVIeXYsvN5AX+y+dl9dyjoJ1fLIJBkpFseOFuelAD0ivBrbi6gJuoXqonyE= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791549324; 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=exhayY0m7PuTyE0K3zCSPt0nz56nvK55ZSye7k4dp3q/xQ1fy3NMSoESRdjGVZO+ZSasiUWemAqdt/QUrhLHS4eL1tMQ0Gm0fpjYH/geYpBTRDyEH0zeskpEzaipuNMC/li0vx5040QvsJlFGg8NxtnLpKLUImWqJ1+0OpWGDF8= 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=d63nHOOA; 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="d63nHOOA" ARC-Seal: i=1; a=rsa-sha256; t=1791549285; cv=none; d=zohomail.com; s=zohoarc; b=JFocVP+ATBe47AIFjKrUzPSUIgTyk2QpRuYD3pieD0PtDZd8qq2rkQyCnFNawbvtCWdIA+R45j4k9r+gI7QUsdMqfwjCz36kWLPfZ/f2+kT34O9+ksasoDeWgplGVUDeNiubCCKNixxdRdF/cWsxe4K9qO3o+/QZAoGPktaf9mU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791549285; 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=YqiF3RoMs9yJcTNdOCsC6I9DBUfbWgGdyz+dLgF4fX9oEXqrgSlBkv9QpyTZnIo3LlET9hh65k9jVTE7uBrnEqzePeMDOkZ+tOYk+lubinXyhzuDfuJnPKCdQH/eAkW91l5sa3arS4aPmKz5ievSkQV3q++/0pwETvk73RTOHkU= 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=1791549285; 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=d63nHOOA29LbJpwAP5oHpb1Jn78dlauMFSO9/uolxR+CRng6d22Xkhgt4idlTaNK lqreiA5IDLYuOJu1j4lt1WvuWpOPgkIMATxI9VjOxYl2miS7PnwOSK5umZm3uKtlAIt 1E8hxO7pn0DIMo2XQSWol21nB3nfpjo2IkbexKzs= Received: by smtp.zohomail.com with SMTPS id 1791549284309132.96649183999114; Fri, 9 Oct 2026 05:34:44 -0700 (PDT) From: =?utf-8?q?Adri=C3=A1n_Larumbe?= Date: Fri, 09 Oct 2026 13:33:55 +0100 Subject: [PATCH v14 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: <20261009-claude-fixes-v14-8-cb743b3b973b@collabora.com> References: <20261009-claude-fixes-v14-0-cb743b3b973b@collabora.com> In-Reply-To: <20261009-claude-fixes-v14-0-cb743b3b973b@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=kA0DAAoBDiZ+TO5TQz0ByyZiAGrI3y+hjmC2ZbuKWcu1RDvy3/2m5kDGLMXkHYnIWY/NRCySw YkBswQAAQoAHRYhBDJAMOjABRdd+TcHpA4mfkzuU0M9BQJqyN8vAAoJEA4mfkzuU0M9T8QMALts cAVQfWBomeQHrf54u7WjLo3+OPR8cAQvUid21Kh7Yj9sv+1eTHnprjktoxDfhJJixa7Bw0O4DzO dRAThWMiMFhJcgXrosax4Eed1t3QzH2GMLk0XLO0Rtg+YjfzCO8IGwLBrhmkgpLiXe4WRFRUpx8 qDjjXzrCcAVJuVFdBXVBQv/6RGppCzjltp2rcXXwh/UNpo6OBh1Ac/8PRr2A0exJXsAPhYZJp2F hfX1SQoFUS7G7Iz2RTu1L9uotKjzGS4ipGQOaRmQBTzd77K0w0zhlfLpngr5KNWuMt37Tcn/fN5 EKxW8c37vpoWqjoDFzvSMpZGnzhzx9NwuhlGZxpizuHp1a8PEuj2WrfhtWU/r3c29PMVc2NKBb5 LvmQ1dEAr8GDxRSGAeoElcvRC/iw6jvmLwrnRxSC8kDG8Kad+cwUkDSNhKKK2MzqjrnnBT/aBug i5NMOgkXPwp/n9O2hOzqR57rvUf3DextZeBYVurtS0Y3D5MmVRvia31kYMwA== 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