git: e138f36f6422 - stable/14 - LinuxKPI: add general module_driver(), use it for module_pci_driver()

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sat, 28 Sep 2024 10:38:24 UTC
The branch stable/14 has been updated by bz:

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

commit e138f36f6422212ac8b459ecfb2f0677404a3a7d
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2024-08-28 14:21:33 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2024-09-28 10:35:14 +0000

    LinuxKPI: add general module_driver(), use it for module_pci_driver()
    
    Factor out module_pci_driver() from 366d68f283793 into a general
    module_driver() so other bus attachments can also use the same kind
    of macro without duplicating all the lines.
    
    Redefine module_pci_driver() using the new general macro.
    
    No functional changes intended.
    
    Sponsored by:   The FreeBSD Foundation
    Reviewed by:    manu
    Differential Revision: https://reviews.freebsd.org/D46467
    
    (cherry picked from commit f5c7feee7129dc88a2e5dc3ce0a075cb5e4f534a)
---
 .../linuxkpi/common/include/linux/device/driver.h  | 33 ++++++++++++++++++++++
 sys/compat/linuxkpi/common/include/linux/pci.h     | 21 ++------------
 2 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/device/driver.h b/sys/compat/linuxkpi/common/include/linux/device/driver.h
new file mode 100644
index 000000000000..03b510c9c8b7
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/device/driver.h
@@ -0,0 +1,33 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2021 Bjoern A. Zeeb
+ * Copyright (c) 2024 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
+ */
+
+#ifndef	LINUXKPI_LINUX_DEVICE_DRIVER_H
+#define	LINUXKPI_LINUX_DEVICE_DRIVER_H
+
+#include <sys/cdefs.h>
+#include <linux/module.h>
+
+#define	module_driver(_drv, _regf, _unregf)					\
+static inline int								\
+__CONCAT(__CONCAT(_, _drv), _init)(void)					\
+{										\
+	return (_regf(&(_drv)));		 				\
+}										\
+										\
+static inline void								\
+__CONCAT(__CONCAT(_, _drv), _exit)(void)					\
+{										\
+	_unregf(&(_drv));							\
+}										\
+										\
+module_init(__CONCAT(__CONCAT(_, _drv), _init));				\
+module_exit(__CONCAT(__CONCAT(_, _drv), _exit))
+
+#endif	/* LINUXKPI_LINUX_DEVICE_DRIVER_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h
index f9b60ae186b5..73882b312db5 100644
--- a/sys/compat/linuxkpi/common/include/linux/pci.h
+++ b/sys/compat/linuxkpi/common/include/linux/pci.h
@@ -36,6 +36,7 @@
 #define	CONFIG_PCI_MSI
 
 #include <linux/types.h>
+#include <linux/device/driver.h>
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -274,24 +275,8 @@ extern spinlock_t pci_lock;
 
 #define	__devexit_p(x)	x
 
-#define module_pci_driver(_driver)					\
-									\
-static inline int							\
-_pci_init(void)								\
-{									\
-									\
-	return (linux_pci_register_driver(&_driver));			\
-}									\
-									\
-static inline void							\
-_pci_exit(void)								\
-{									\
-									\
-	linux_pci_unregister_driver(&_driver);				\
-}									\
-									\
-module_init(_pci_init);							\
-module_exit(_pci_exit)
+#define	module_pci_driver(_drv)						\
+    module_driver(_drv, linux_pci_register_driver, linux_pci_unregister_driver)
 
 struct msi_msg {
 	uint32_t			data;