git: e93eb7b7f821 - stable/15 - linuxkpi: Define `MINORBITS`

From: Jean-Sébastien Pédron <dumbbell_at_FreeBSD.org>
Date: Wed, 29 Apr 2026 21:42:48 UTC
The branch stable/15 has been updated by dumbbell:

URL: https://cgit.FreeBSD.org/src/commit/?id=e93eb7b7f821160958261e5678f5bafde8237a84

commit e93eb7b7f821160958261e5678f5bafde8237a84
Author:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2026-04-13 21:47:22 +0000
Commit:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
CommitDate: 2026-04-29 21:03:18 +0000

    linuxkpi: Define `MINORBITS`
    
    We can't really define a proper value for this constant because minor
    and major are encoded in a complex way on FreeBSD which cannot be
    represented with a simple shift.
    
    The DRM generic code started to use it in Linux 6.12.
    
    In this context, `MINORBITS` is used to define an upper limit passed to
    `xa_alloc()`. Therefore it is not used to encode or decode minors. It is
    used as an arbitrary value. Therefore, we define the constant to 20,
    like on Linux.
    
    Reviewed by:    bz
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit ae1f6954e2c82ad7f1d8b80155a921b908d51756)
---
 sys/compat/linuxkpi/common/include/linux/kdev_t.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/kdev_t.h b/sys/compat/linuxkpi/common/include/linux/kdev_t.h
index 988dd771254a..964b7078e7f5 100644
--- a/sys/compat/linuxkpi/common/include/linux/kdev_t.h
+++ b/sys/compat/linuxkpi/common/include/linux/kdev_t.h
@@ -31,6 +31,21 @@
 
 #include <sys/types.h>
 
+/*
+ * The encoding of major/minor on FreeBSD is complex to take into account the
+ * compatibility with 16-bit dev_t (see <sys/types.h>). It is not possible to
+ * use a simple shift and thus, we can't have a proper definition of
+ * `MINORBITS`.
+ *
+ * At the time this is added to linuxkpi, this is used by the DRM generic code
+ * as the upper limit to allocate an ID using an xarray. It is not used to
+ * decode a minor, therefore any arbitrary value here is fine in this context.
+ *
+ * On Linux, the value is set to 20. Because of the above, we reuse this value,
+ * even so it does not correspond to the actual minor encoding on FreeBSD.
+ */
+#define MINORBITS	20
+
 #define MAJOR(dev)      major(dev)
 #define MINOR(dev)      minor(dev)
 #define MKDEV(ma, mi)   makedev(ma, mi)