From: Rob Clark <robin.clark@oss.qualcomm.com>
To: dri-devel@lists.freedesktop.org
Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org,
Rob Clark <robin.clark@oss.qualcomm.com>,
Sean Paul <sean@poorly.run>,
Konrad Dybcio <konradybcio@kernel.org>,
Akhil P Oommen <akhilpo@oss.qualcomm.com>,
Dmitry Baryshkov <lumag@kernel.org>,
Abhinav Kumar <abhinav.kumar@linux.dev>,
Jessica Zhang <jesszhan0024@gmail.com>,
Marijn Suijten <marijn.suijten@somainline.org>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Mahadevan P <mahadevan.p@oss.qualcomm.com>,
Luca Ceresoli <luca.ceresoli@bootlin.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [RFT PATCH v2] drm/msm: Fix separate_gpu_kms for multi-gpu
Date: Thu, 3 Dec 2026 14:28:58 -0800 [thread overview]
Message-ID: <20261203222900.28311-1-robin.clark@oss.qualcomm.com> (raw)
The auto mode was falling back to separate devices if the # of GPUs
or # of displays was greater than 1. Rework this so that we pair
up displays and GPUs until we run out of one or the other, and then
create standalone devices for anything remaining.
Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com>
---
drivers/gpu/drm/msm/adreno/adreno_device.c | 4 +-
drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 9 ++-
drivers/gpu/drm/msm/msm_drv.c | 91 ++++++++++++++--------
drivers/gpu/drm/msm/msm_drv.h | 10 +--
drivers/gpu/drm/msm/msm_mdss.c | 9 ++-
5 files changed, 79 insertions(+), 44 deletions(-)
diff --git a/drivers/gpu/drm/msm/adreno/adreno_device.c b/drivers/gpu/drm/msm/adreno/adreno_device.c
index a3b2440a1a27..bf401dcceb30 100644
--- a/drivers/gpu/drm/msm/adreno/adreno_device.c
+++ b/drivers/gpu/drm/msm/adreno/adreno_device.c
@@ -272,7 +272,7 @@ static int adreno_probe(struct platform_device *pdev)
{
int ret;
- if (!msm_separate_gpu_kms_components())
+ if (!msm_separate_gpu_kms_components(&pdev->dev, true))
return component_add(&pdev->dev, &a3xx_ops);
if (!adreno_has_gpu(pdev->dev.of_node))
@@ -292,7 +292,7 @@ static int adreno_probe(struct platform_device *pdev)
static void adreno_remove(struct platform_device *pdev)
{
component_del(&pdev->dev, &a3xx_ops);
- if (msm_separate_gpu_kms_components())
+ if (msm_separate_gpu_kms_components(&pdev->dev, true))
msm_gpu_remove(pdev);
}
diff --git a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
index ad08a040982f..8bff3a075c79 100644
--- a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
+++ b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
@@ -16,14 +16,19 @@
#include "mdp4_kms.h"
static const struct of_device_id mdp4_dt_match[];
-int msm_count_mdp4(void)
+int msm_count_mdp4(struct device_node *target_np)
{
struct device_node *np;
int count = 0;
for_each_matching_node(np, mdp4_dt_match) {
- if (of_device_is_available(np))
+ if (of_device_is_available(np)) {
count++;
+ if (target_np == np) {
+ of_node_put(np);
+ return count;
+ }
+ }
}
return count;
diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index cd59daa02bf9..f7a0d43cd06b 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -56,16 +56,15 @@ MODULE_PARM_DESC(modeset, "Use kernel modesetting [KMS] (1=on (default), 0=disab
module_param(modeset, bool, 0600);
/*
- * separate_gpu_kms (tristate):
- * -1 (default): decide automatically based on hardware topology. Split devices
- * if there is more than one GPU or more than one display master.
- * 0: force single DRM device (bind display + GPU)
- * 1: force separate DRM devices
+ * When not using separate gpu and kms devices, the display and gpu devices
+ * are #'d, with the n'th gpu being paired off with the n'th display, until
+ * we run out of gpu or display devices at which point any remaining devices
+ * are stand-alone (ie. either gpu-only or display-only).
*/
-static int separate_gpu_kms = -1;
+static bool separate_gpu_kms = 0;
MODULE_PARM_DESC(separate_gpu_kms,
- "Use separate DRM device for the GPU (-1=auto (default), 0=single DRM device, 1=separate DRM devices)");
-module_param(separate_gpu_kms, int, 0400);
+ "Use separate DRM device for the GPU (0=single DRM device per pair of GPU+DPU, 1=separate DRM devices)");
+module_param(separate_gpu_kms, bool, 0400);
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
static bool transparent_hugepage = true;
@@ -98,43 +97,53 @@ static inline bool msm_gpu_node_present(struct device_node *np)
return np && of_device_is_available(np) && adreno_has_gpu(np);
}
-static int msm_count_gpus(void)
+static int msm_count_gpus(struct device_node *target_np)
{
struct device_node *np;
int count = 0;
for_each_matching_node(np, msm_gpu_match) {
- if (msm_gpu_node_present(np))
+ if (msm_gpu_node_present(np)) {
count++;
+ if (target_np == np) {
+ of_node_put(np);
+ return count;
+ }
+ }
}
return count;
}
-static bool msm_separate_gpu_kms_auto(void)
+static int msm_display_idx(struct device *dev)
{
- int gpus = msm_count_gpus();
- int display_subsystems = msm_count_mdss() + msm_count_mdp4();
+ int disp_idx = msm_count_mdp4(dev->of_node);
- /* Single card if there is exactly one GPU and one display subsystem */
- if (gpus == 1 && display_subsystems == 1)
- return false;
+ if (dev->parent)
+ disp_idx += msm_count_mdss(dev->parent->of_node);
- return true;
+ return disp_idx;
}
-bool msm_separate_gpu_kms_components(void)
+bool msm_separate_gpu_kms_components(struct device *dev, bool is_gpu)
{
- if (msm_count_gpus() == 0)
+ if (separate_gpu_kms)
return true;
- switch (separate_gpu_kms) {
- case 0:
- return false;
- case 1:
- return true;
- default:
- return msm_separate_gpu_kms_auto();
+ if (is_gpu) {
+ int gpu_idx = msm_count_gpus(dev->of_node);
+ int num_disp = msm_count_mdp4(NULL) + msm_count_mdss(NULL);
+
+ pr_err("%s: gpu: %u > %u\n", __func__, gpu_idx, num_disp);
+
+ return gpu_idx > num_disp;
+ } else {
+ int num_gpu = msm_count_gpus(NULL);
+ int disp_idx = msm_display_idx(dev);
+
+ pr_err("%s: display: %u > %u\n", __func__, disp_idx, num_gpu);
+
+ return disp_idx > num_gpu;
}
}
@@ -1099,8 +1108,7 @@ static int add_gpu_components(struct device *dev,
struct device_node *gpu_np,
struct component_match **matchptr)
{
- struct device_node *np __free(device_node) = gpu_np ?
- of_node_get(gpu_np) : of_find_matching_node(NULL, msm_gpu_match);
+ struct device_node *np __free(device_node) = of_node_get(gpu_np);
if (!np || !msm_gpu_node_present(np))
return 0;
@@ -1121,7 +1129,7 @@ static int msm_drm_bind(struct device *dev)
if (!priv->kms_init)
drv = &msm_gpu_driver;
- else if (msm_separate_gpu_kms_components())
+ else if (msm_separate_gpu_kms_components(dev, false))
drv = &msm_kms_driver;
else
drv = &msm_driver;
@@ -1164,10 +1172,27 @@ int msm_drv_probe(struct device *master_dev,
return ret;
}
- if (!kms_init || !msm_separate_gpu_kms_components()) {
- ret = add_gpu_components(master_dev, gpu_np, &match);
- if (ret)
- return ret;
+ if (!kms_init || !msm_separate_gpu_kms_components(master_dev, false)) {
+ if (gpu_np) {
+ ret = add_gpu_components(master_dev, gpu_np, &match);
+ if (ret)
+ return ret;
+ } else {
+ int disp_idx = msm_display_idx(master_dev);
+ struct device_node *np;
+
+ /* If we are the display, try adding the matching gpu: */
+ for_each_matching_node (np, msm_gpu_match) {
+ if (disp_idx != msm_count_gpus(np))
+ continue;
+ ret = add_gpu_components(master_dev, np, &match);
+ if (ret)
+ return ret;
+ pr_err("%s: matched: %s + %s\n", __func__,
+ of_node_full_name(master_dev->of_node),
+ of_node_full_name(np));
+ }
+ }
}
/* on all devices that I am aware of, iommu's which can map
diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h
index b65702ac0140..628eb9965704 100644
--- a/drivers/gpu/drm/msm/msm_drv.h
+++ b/drivers/gpu/drm/msm/msm_drv.h
@@ -394,11 +394,11 @@ static inline bool msm_dp_wide_bus_available(const struct msm_dp *dp_display)
#ifdef CONFIG_DRM_MSM_MDP4
void msm_mdp4_register(void);
void msm_mdp4_unregister(void);
-int msm_count_mdp4(void);
+int msm_count_mdp4(struct device_node *target_np);
#else
static inline void msm_mdp4_register(void) {}
static inline void msm_mdp4_unregister(void) {}
-static inline int msm_count_mdp4(void) { return 0; }
+static inline int msm_count_mdp4(struct device_node *target_np) { return 0; }
#endif
#ifdef CONFIG_DRM_MSM_MDP5
@@ -420,11 +420,11 @@ static inline void msm_dpu_unregister(void) {}
#ifdef CONFIG_DRM_MSM_MDSS
void msm_mdss_register(void);
void msm_mdss_unregister(void);
-int msm_count_mdss(void);
+int msm_count_mdss(struct device_node *target_np);
#else
static inline void msm_mdss_register(void) {}
static inline void msm_mdss_unregister(void) {}
-static inline int msm_count_mdss(void) { return 0; }
+static inline int msm_count_mdss(struct device_node *target_np) { return 0; }
#endif
#ifdef CONFIG_DEBUG_FS
@@ -539,6 +539,6 @@ void msm_kms_shutdown(struct platform_device *pdev);
bool msm_disp_drv_should_bind(struct device *dev, bool dpu_driver);
-bool msm_separate_gpu_kms_components(void);
+bool msm_separate_gpu_kms_components(struct device *dev, bool is_gpu);
#endif /* __MSM_DRV_H__ */
diff --git a/drivers/gpu/drm/msm/msm_mdss.c b/drivers/gpu/drm/msm/msm_mdss.c
index fb0261ae9c78..506ae31c5587 100644
--- a/drivers/gpu/drm/msm/msm_mdss.c
+++ b/drivers/gpu/drm/msm/msm_mdss.c
@@ -77,14 +77,19 @@ static int msm_mdss_parse_data_bus_icc_path(struct device *dev,
static const struct of_device_id mdss_dt_match[];
-int msm_count_mdss(void)
+int msm_count_mdss(struct device_node *target_np)
{
struct device_node *np;
int count = 0;
for_each_matching_node(np, mdss_dt_match) {
- if (of_device_is_available(np))
+ if (of_device_is_available(np)) {
count++;
+ if (target_np == np) {
+ of_node_put(np);
+ return count;
+ }
+ }
}
return count;
--
2.56.1
reply other threads:[~2026-12-03 22:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203222900.28311-1-robin.clark@oss.qualcomm.com \
--to=robin.clark@oss.qualcomm.com \
--cc=abhinav.kumar@linux.dev \
--cc=airlied@gmail.com \
--cc=akhilpo@oss.qualcomm.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=jesszhan0024@gmail.com \
--cc=konradybcio@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=lumag@kernel.org \
--cc=mahadevan.p@oss.qualcomm.com \
--cc=marijn.suijten@somainline.org \
--cc=sean@poorly.run \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®