git: 5f684c7cb8ee - stable/13 - Deprecate the 'devclass' argument from *DRIVER_MODULE() macros.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Tue, 17 May 2022 23:38:11 UTC
The branch stable/13 has been updated by jhb:

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

commit 5f684c7cb8ee9a1dfb5263514738aca3704660dd
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-04-19 17:43:06 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-05-17 21:17:18 +0000

    Deprecate the 'devclass' argument from *DRIVER_MODULE() macros.
    
    This argument is useless for the vast majority of drivers.  For now,
    use __VA_ARGS__ wrapper macros so that that the *DRIVER_MODULE()
    macros accept both the old version (with a devclass) and the new
    version (which omits the argument and stores NULL in the
    driver_module_data structure).  This provides an API compatiblity
    shim that can be merged to older stable branches.
    
    Once all drivers relevant to 14.0 (both in and out of tree) have been
    updated, the API compat shims can be dropped.
    
    Reviewed by:    imp
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D34963
    
    (cherry picked from commit 2a99dd30dfaac98fea79f084b3a13c45199e1348)
    (cherry picked from commit 0fdf5bc531fbde4fa80a85614ba40230062ebde4)
    (cherry picked from commit b7d4192598fed6581be627fc767f06a62195dfd5)
---
 share/man/man9/DRIVER_MODULE.9 | 26 ++++++++++---------
 share/man/man9/driver.9        |  6 ++---
 sys/sys/bus.h                  | 57 ++++++++++++++++++++++++++++++++++++------
 3 files changed, 65 insertions(+), 24 deletions(-)

diff --git a/share/man/man9/DRIVER_MODULE.9 b/share/man/man9/DRIVER_MODULE.9
index 5d5927fba1e8..15f4a87c2276 100644
--- a/share/man/man9/DRIVER_MODULE.9
+++ b/share/man/man9/DRIVER_MODULE.9
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 24, 2021
+.Dd April 19, 2022
 .Dt DRIVER_MODULE 9
 .Os
 .Sh NAME
@@ -42,10 +42,10 @@
 .In sys/kernel.h
 .In sys/bus.h
 .In sys/module.h
-.Fn DRIVER_MODULE name busname "driver_t driver" "devclass_t devclass" "modeventhand_t evh" "void *arg"
-.Fn DRIVER_MODULE_ORDERED name busname "driver_t driver" "devclass_t devclass" "modeventhand_t evh" "void *arg" "int order"
-.Fn EARLY_DRIVER_MODULE name busname "driver_t driver" "devclass_t devclass" "modeventhand_t evh" "void *arg" "int pass"
-.Fn EARLY_DRIVER_MODULE_ORDERED name busname "driver_t driver" "devclass_t devclass" "modeventhand_t evh" "void *arg" "enum sysinit_elem_order order" "int pass"
+.Fn DRIVER_MODULE name busname "driver_t driver" "modeventhand_t evh" "void *arg"
+.Fn DRIVER_MODULE_ORDERED name busname "driver_t driver" "modeventhand_t evh" "void *arg" "int order"
+.Fn EARLY_DRIVER_MODULE name busname "driver_t driver" "modeventhand_t evh" "void *arg" "int pass"
+.Fn EARLY_DRIVER_MODULE_ORDERED name busname "driver_t driver" "modeventhand_t evh" "void *arg" "enum sysinit_elem_order order" "int pass"
 .Sh DESCRIPTION
 The
 .Fn DRIVER_MODULE
@@ -74,9 +74,9 @@ which is a pretty clean way of making front ends for different cards
 using the same driver on the same or different buses.
 For example, the following is allowed:
 .Pp
-.Fn DRIVER_MODULE foo isa foo_driver foo_devclass NULL NULL ;
+.Fn DRIVER_MODULE foo isa foo_driver NULL NULL ;
 .Pp
-.Fn DRIVER_MODULE foo pci foo_driver foo_devclass NULL NULL ;
+.Fn DRIVER_MODULE foo pci foo_driver NULL NULL ;
 .Pp
 .Fa driver
 is the driver of type
@@ -86,11 +86,6 @@ two most important parts of the call to
 .Fn DRIVER_MODULE .
 .Pp
 The
-.Fa devclass
-argument contains the kernel-internal information about the device,
-which will be used within the kernel driver module.
-.Pp
-The
 .Fa evh
 argument is the event handler which is called when the driver (or module)
 is loaded or unloaded (see
@@ -146,6 +141,13 @@ for a specific pass level.
 .Xr module 9 ,
 .Xr MODULE_PNP_INFO 9 ,
 .Xr SYSINIT 9
+.Sh HISTORY
+Prior to
+.Fx 14.0 ,
+these macros accepted an additional
+.Vt devclass_t
+argument after
+.Fa driver .
 .Sh AUTHORS
 This manual page was written by
 .An Alexander Langer Aq Mt alex@FreeBSD.org .
diff --git a/share/man/man9/driver.9 b/share/man/man9/driver.9
index e801a188c732..5c47e39eb3d9 100644
--- a/share/man/man9/driver.9
+++ b/share/man/man9/driver.9
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd April 30, 2020
+.Dd April 19, 2022
 .Dt DRIVER 9
 .Os
 .Sh NAME
@@ -67,9 +67,7 @@ static driver_t foo_driver = {
 	sizeof(struct foo_softc)
 };
 
-static devclass_t foo_devclass;
-
-DRIVER_MODULE(foo, bogo, foo_driver, foo_devclass, NULL, NULL);
+DRIVER_MODULE(foo, bogo, foo_driver, NULL, NULL);
 .Ed
 .Sh DESCRIPTION
 Each driver in the kernel is described by a
diff --git a/sys/sys/bus.h b/sys/sys/bus.h
index 1fc7fdf25aca..af2be5c5583b 100644
--- a/sys/sys/bus.h
+++ b/sys/sys/bus.h
@@ -779,14 +779,17 @@ struct driver_module_data {
 	int		dmd_pass;
 };
 
-#define	EARLY_DRIVER_MODULE_ORDERED(name, busname, driver, devclass,	\
+#define	_DRIVER_MODULE_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...)	\
+	NAME
+
+#define	_EARLY_DRIVER_MODULE_ORDERED(name, busname, driver, devclass,	\
     evh, arg, order, pass)						\
 									\
 static struct driver_module_data name##_##busname##_driver_mod = {	\
 	evh, arg,							\
 	#busname,							\
 	(kobj_class_t) &driver,						\
-	&devclass,							\
+	devclass,							\
 	pass								\
 };									\
 									\
@@ -798,19 +801,57 @@ static moduledata_t name##_##busname##_mod = {				\
 DECLARE_MODULE(name##_##busname, name##_##busname##_mod,		\
 	       SI_SUB_DRIVERS, order)
 
-#define	EARLY_DRIVER_MODULE(name, busname, driver, devclass, evh, arg, pass) \
-	EARLY_DRIVER_MODULE_ORDERED(name, busname, driver, devclass,	\
+#define	EARLY_DRIVER_MODULE_ORDERED7(name, busname, driver, evh, arg,	\
+    order, pass)							\
+	_EARLY_DRIVER_MODULE_ORDERED(name, busname, driver, NULL, evh,	\
+	    arg, order, pass)
+
+#define	EARLY_DRIVER_MODULE_ORDERED8(name, busname, driver, devclass,	\
+    evh, arg, order, pass)						\
+	_EARLY_DRIVER_MODULE_ORDERED(name, busname, driver, &devclass,	\
+	    evh, arg, order, pass)
+
+#define	EARLY_DRIVER_MODULE_ORDERED(...)				\
+	_DRIVER_MODULE_MACRO(__VA_ARGS__, EARLY_DRIVER_MODULE_ORDERED8,	\
+	    EARLY_DRIVER_MODULE_ORDERED7)(__VA_ARGS__)
+
+#define	EARLY_DRIVER_MODULE7(name, busname, driver, devclass, evh, arg, pass) \
+	EARLY_DRIVER_MODULE_ORDERED8(name, busname, driver, devclass,	\
 	    evh, arg, SI_ORDER_MIDDLE, pass)
 
-#define	DRIVER_MODULE_ORDERED(name, busname, driver, devclass, evh, arg,\
+#define	EARLY_DRIVER_MODULE6(name, busname, driver, evh, arg, pass)	\
+	EARLY_DRIVER_MODULE_ORDERED7(name, busname, driver, evh, arg,	\
+	    SI_ORDER_MIDDLE, pass)
+
+#define	EARLY_DRIVER_MODULE(...)					\
+	_DRIVER_MODULE_MACRO(__VA_ARGS__, INVALID,			\
+	    EARLY_DRIVER_MODULE7, EARLY_DRIVER_MODULE6)(__VA_ARGS__)
+
+#define	DRIVER_MODULE_ORDERED7(name, busname, driver, devclass, evh, arg,\
     order)								\
-	EARLY_DRIVER_MODULE_ORDERED(name, busname, driver, devclass,	\
+	EARLY_DRIVER_MODULE_ORDERED8(name, busname, driver, devclass,	\
 	    evh, arg, order, BUS_PASS_DEFAULT)
 
-#define	DRIVER_MODULE(name, busname, driver, devclass, evh, arg)	\
-	EARLY_DRIVER_MODULE(name, busname, driver, devclass, evh, arg,	\
+#define	DRIVER_MODULE_ORDERED6(name, busname, driver, evh, arg, order)	\
+	EARLY_DRIVER_MODULE_ORDERED7(name, busname, driver, evh, arg,	\
+	    order, BUS_PASS_DEFAULT)
+
+#define	DRIVER_MODULE_ORDERED(...)					\
+	_DRIVER_MODULE_MACRO(__VA_ARGS__, INVALID,			\
+	    DRIVER_MODULE_ORDERED7, DRIVER_MODULE_ORDERED6)(__VA_ARGS__)
+
+#define	DRIVER_MODULE6(name, busname, driver, devclass, evh, arg)	\
+	EARLY_DRIVER_MODULE7(name, busname, driver, devclass, evh, arg,	\
 	    BUS_PASS_DEFAULT)
 
+#define	DRIVER_MODULE5(name, busname, driver, evh, arg)			\
+	EARLY_DRIVER_MODULE6(name, busname, driver, evh, arg,		\
+	    BUS_PASS_DEFAULT)
+
+#define	DRIVER_MODULE(...)						\
+	_DRIVER_MODULE_MACRO(__VA_ARGS__, INVALID, INVALID,		\
+	    DRIVER_MODULE6, DRIVER_MODULE5)(__VA_ARGS__)
+
 /**
  * Generic ivar accessor generation macros for bus drivers
  */