<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 2023-07-24 17:14, Michał Winiarski
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:20230724211428.3831636-4-michal.winiarski@intel.com">
      <pre class="moz-quote-pre" wrap="">Having a limit of 64 DRM devices is not good enough for modern world
where we have multi-GPU servers, SR-IOV virtual functions and virtual
devices used for testing.
Let's utilize full minor range for DRM devices.
To avoid regressing the existing userspace, we're still maintaining the
numbering scheme where 0-63 is used for primary, 64-127 is reserved
(formerly for control) and 128-191 is used for render.
For minors >= 192, we're allocating minors dynamically on a first-come,
first-served basis.</pre>
    </blockquote>
    <p>[JZ] Hello Michal,</p>
    <p>Do you have libdrm patches for review together with this change?</p>
    <p>Especially to support <span style="color: rgb(137, 136, 141);
        font-family: "JetBrains Mono", Menlo, "DejaVu
        Sans Mono", "Liberation Mono", Consolas,
        "Ubuntu Mono", "Courier New", "andale
        mono", "lucida console", monospace; font-size:
        12.6px; font-style: normal; font-variant-ligatures: none;
        font-variant-caps: normal; font-weight: 400; letter-spacing:
        normal; orphans: 2; text-align: left; text-indent: 0px;
        text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-stroke-width: 0px;
        background-color: rgb(236, 236, 239); text-decoration-thickness:
        initial; text-decoration-style: initial; text-decoration-color:
        initial; display: inline !important; float: none;">static int
        drmGetMinorType(int major, int minor).</span></p>
    <p>Thanks and Best Regards!</p>
    <p>James Zhu <span style="color: rgb(137, 136, 141); font-family:
        "JetBrains Mono", Menlo, "DejaVu Sans Mono",
        "Liberation Mono", Consolas, "Ubuntu Mono",
        "Courier New", "andale mono", "lucida
        console", monospace; font-size: 12.6px; font-style: normal;
        font-variant-ligatures: none; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: left; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(236, 236,
        239); text-decoration-thickness: initial; text-decoration-style:
        initial; text-decoration-color: initial; display: inline
        !important; float: none;"></span></p>
    <blockquote type="cite" cite="mid:20230724211428.3831636-4-michal.winiarski@intel.com">
      <pre class="moz-quote-pre" wrap="">

Signed-off-by: Michał Winiarski <a class="moz-txt-link-rfc2396E" href="mailto:michal.winiarski@intel.com"><michal.winiarski@intel.com></a>
---
 drivers/gpu/drm/drm_drv.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 34b60196c443..c2c6e80e6b31 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -121,10 +121,19 @@ static void drm_minor_alloc_release(struct drm_device *dev, void *data)
        xa_erase(drm_minor_get_xa(minor->type), minor->index);
 }
 
+/*
+ * DRM used to support 64 devices, for backwards compatibility we need to maintain the
+ * minor allocation scheme where minors 0-63 are primary nodes, 64-127 are control nodes,
+ * and 128-191 are render nodes.
+ * After reaching the limit, we're allocating minors dynamically - first-come, first-serve.
+ * Accel nodes are using a distinct major, so the minors are allocated in continuous 0-MAX
+ * range.
+ */
 #define DRM_MINOR_LIMIT(t) ({ \
        typeof(t) _t = (t); \
        _t == DRM_MINOR_ACCEL ? XA_LIMIT(0, ACCEL_MAX_MINORS) : XA_LIMIT(64 * _t, 64 * _t + 63); \
 })
+#define DRM_EXTENDED_MINOR_LIMIT XA_LIMIT(192, (1 << MINORBITS) - 1)
 
 static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type)
 {
@@ -140,6 +149,9 @@ static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type)
 
        r = xa_alloc(drm_minor_get_xa(type), &minor->index,
                     NULL, DRM_MINOR_LIMIT(type), GFP_KERNEL);
+       if (r == -EBUSY && (type == DRM_MINOR_PRIMARY || type == DRM_MINOR_RENDER))
+               r = xa_alloc(&drm_minors_xa, &minor->index,
+                            NULL, DRM_EXTENDED_MINOR_LIMIT, GFP_KERNEL);
        if (r < 0)
                return r;
 
</pre>
    </blockquote>
  </body>
</html>