devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm: support gpu aliases defined in DT data
@ 2019-01-17 11:19 Tomi Valkeinen
  2019-01-17 11:35 ` Maxime Ripard
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Tomi Valkeinen @ 2019-01-17 11:19 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Sean Paul, David Airlie,
	Daniel Vetter, dri-devel, Rob Herring, devicetree,
	Laurent Pinchart
  Cc: Tomi Valkeinen

The DRM device minor numbers are allocated according to the registration
order. This causes confusion in cases where the registration order can
change, or when, say, a modesetting capable device is preferred to be
card0, and a rendering device is preferred to be card1.

This patch adds similar functionality that is used in some other
subsystems, where device minor numbers can be defined in DT bindings'
aliases node.

For example, this sets the DRM device minor number to 1 for the 'dss'
device.

aliases {
	gpu1 = &dss;
};

The logic on how to pick the minor number is:

- if there's a DT gpu alias for the device, use that
- else, if there are any gpu aliases, pick a minor number that is higher
  than any of the aliases.
- else, use the full range of possible numbers

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
---
 drivers/gpu/drm/drm_drv.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index a5fe91b8c3c9..f536a2760293 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -110,6 +110,8 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type)
 	struct drm_minor *minor;
 	unsigned long flags;
 	int r;
+	int min_id, max_id;
+	bool of_id_found = false;
 
 	minor = kzalloc(sizeof(*minor), GFP_KERNEL);
 	if (!minor)
@@ -118,12 +120,37 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type)
 	minor->type = type;
 	minor->dev = dev;
 
+	min_id = 64 * type;
+	max_id = 64 * (type + 1);
+
+	if (dev->dev && dev->dev->of_node) {
+		int id;
+
+		id = of_alias_get_id(dev->dev->of_node, "gpu");
+
+		if (id >= 0) {
+			min_id = 64 * type + id;
+			max_id = 64 * type + id + 1;
+
+			of_id_found = true;
+		}
+	}
+
+	if (!of_id_found) {
+		int id;
+
+		id = of_alias_get_highest_id("gpu");
+
+		if (id >= 0)
+			min_id = id + 1;
+	}
+
 	idr_preload(GFP_KERNEL);
 	spin_lock_irqsave(&drm_minor_lock, flags);
 	r = idr_alloc(&drm_minors_idr,
 		      NULL,
-		      64 * type,
-		      64 * (type + 1),
+		      min_id,
+		      max_id,
 		      GFP_NOWAIT);
 	spin_unlock_irqrestore(&drm_minor_lock, flags);
 	idr_preload_end();
-- 
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-04-26 11:23 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-17 11:19 [PATCH] drm: support gpu aliases defined in DT data Tomi Valkeinen
2019-01-17 11:35 ` Maxime Ripard
2019-01-17 12:33 ` Daniel Vetter
2019-01-17 13:04   ` Tomi Valkeinen
2019-01-17 13:26     ` Daniel Vetter
2019-01-17 13:56       ` Tomi Valkeinen
2019-01-17 22:04       ` Rob Herring
2019-01-18  8:29         ` Tomi Valkeinen
2019-03-06  1:41           ` Laurent Pinchart
2019-03-06  7:49             ` Tomi Valkeinen
2019-04-17 17:42           ` Emil Velikov
2019-04-26 11:23             ` Tomi Valkeinen
2019-01-17 21:38 ` Eric Anholt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).