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@xxxxxx> --- 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@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel