From: Javier Martinez Canillas <javierm@redhat.com>
To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org
Cc: Thomas Zimmermann <tzimmermann@suse.de>,
Javier Martinez Canillas <javierm@redhat.com>,
Daniel Vetter <daniel@ffwll.ch>, David Airlie <airlied@linux.ie>,
Jonathan Corbet <corbet@lwn.net>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
linux-doc@vger.kernel.org
Subject: [PATCH v3 01/10] drm: Provide PCI module-init macros
Date: Wed, 22 Dec 2021 09:28:22 +0100 [thread overview]
Message-ID: <20211222082831.196562-2-javierm@redhat.com> (raw)
In-Reply-To: <20211222082831.196562-1-javierm@redhat.com>
From: Thomas Zimmermann <tzimmermann@suse.de>
Provide helper macros to register PCI-based DRM drivers. The new
macros behave like module_pci_driver() with an additional test if
DRM modesetting has been enabled.
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
(no changes since v1)
Documentation/gpu/drm-internals.rst | 6 ++
include/drm/drm_module.h | 95 +++++++++++++++++++++++++++++
2 files changed, 101 insertions(+)
create mode 100644 include/drm/drm_module.h
diff --git a/Documentation/gpu/drm-internals.rst b/Documentation/gpu/drm-internals.rst
index 607f78f0f189..38afed24a75c 100644
--- a/Documentation/gpu/drm-internals.rst
+++ b/Documentation/gpu/drm-internals.rst
@@ -75,6 +75,12 @@ update it, its value is mostly useless. The DRM core prints it to the
kernel log at initialization time and passes it to userspace through the
DRM_IOCTL_VERSION ioctl.
+Module Initialization
+---------------------
+
+.. kernel-doc:: include/drm/drm_module.h
+ :doc: overview
+
Managing Ownership of the Framebuffer Aperture
----------------------------------------------
diff --git a/include/drm/drm_module.h b/include/drm/drm_module.h
new file mode 100644
index 000000000000..eb3fd7bcbec9
--- /dev/null
+++ b/include/drm/drm_module.h
@@ -0,0 +1,95 @@
+/* SPDX-License-Identifier: MIT */
+
+#ifndef DRM_MODULE_H
+#define DRM_MODULE_H
+
+#include <linux/pci.h>
+
+#include <drm/drm_drv.h>
+
+/**
+ * DOC: overview
+ *
+ * This library provides helpers registering DRM drivers during module
+ * initialization and shutdown. The provided helpers act like bus-specific
+ * module helpers, such as module_pci_driver(), but respect additional
+ * parameters that control DRM driver registration.
+ *
+ * Below is an example of initializing a DRM driver for a device on the
+ * PCI bus.
+ *
+ * .. code-block:: c
+ *
+ * struct pci_driver my_pci_drv = {
+ * };
+ *
+ * drm_module_pci_driver(my_pci_drv);
+ *
+ * The generated code will test if DRM drivers are enabled and register
+ * the PCI driver my_pci_drv. For more complex module initialization, you
+ * can still use module_init() and module_exit() in your driver.
+ */
+
+/*
+ * PCI drivers
+ */
+
+static inline int __init drm_pci_register_driver(struct pci_driver *pci_drv)
+{
+ if (drm_firmware_drivers_only())
+ return -ENODEV;
+
+ return pci_register_driver(pci_drv);
+}
+
+/**
+ * drm_module_pci_driver - Register a DRM driver for PCI-based devices
+ * @__pci_drv: the PCI driver structure
+ *
+ * Registers a DRM driver for devices on the PCI bus. The helper
+ * macro behaves like module_pci_driver() but tests the state of
+ * drm_firmware_drivers_only(). For more complex module initialization,
+ * use module_init() and module_exit() directly.
+ *
+ * Each module may only use this macro once. Calling it replaces
+ * module_init() and module_exit().
+ */
+#define drm_module_pci_driver(__pci_drv) \
+ module_driver(__pci_drv, drm_pci_register_driver, pci_unregister_driver)
+
+static inline int __init
+drm_pci_register_driver_if_modeset(struct pci_driver *pci_drv, int modeset)
+{
+ if (drm_firmware_drivers_only() && modeset == -1)
+ return -ENODEV;
+ if (modeset == 0)
+ return -ENODEV;
+
+ return pci_register_driver(pci_drv);
+}
+
+static inline void __exit
+drm_pci_unregister_driver_if_modeset(struct pci_driver *pci_drv, int modeset)
+{
+ pci_unregister_driver(pci_drv);
+}
+
+/**
+ * drm_module_pci_driver_if_modeset - Register a DRM driver for PCI-based devices
+ * @__pci_drv: the PCI driver structure
+ * @__modeset: an additional parameter that disables the driver
+ *
+ * This macro is deprecated and only provided for existing drivers. For
+ * new drivers, use drm_module_pci_driver().
+ *
+ * Registers a DRM driver for devices on the PCI bus. The helper macro
+ * behaves like drm_module_pci_driver() with an additional driver-specific
+ * flag. If __modeset is 0, the driver has been disabled, if __modeset is
+ * -1 the driver state depends on the global DRM state. For all other
+ * values, the PCI driver has been enabled. The default should be -1.
+ */
+#define drm_module_pci_driver_if_modeset(__pci_drv, __modeset) \
+ module_driver(__pci_drv, drm_pci_register_driver_if_modeset, \
+ drm_pci_unregister_driver_if_modeset, __modeset)
+
+#endif
--
2.33.1
next prev parent reply other threads:[~2021-12-22 8:28 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-22 8:28 [PATCH v3 00/10] drm: Make drivers to honour the nomodeset parameter Javier Martinez Canillas
2021-12-22 8:28 ` Javier Martinez Canillas [this message]
2021-12-22 8:28 ` [PATCH v3 02/10] drm/ast: Replace module-init boiler-plate code with DRM helpers Javier Martinez Canillas
2021-12-22 8:28 ` [PATCH v3 03/10] drm/bochs: " Javier Martinez Canillas
2021-12-22 10:21 ` Gerd Hoffmann
2021-12-22 12:18 ` Javier Martinez Canillas
2021-12-22 8:28 ` [PATCH v3 04/10] drm/cirrus: " Javier Martinez Canillas
2021-12-22 8:28 ` [PATCH v3 05/10] drm/hisilicon/hibmc: Replace module initialization " Javier Martinez Canillas
2021-12-22 8:28 ` [PATCH v3 06/10] drm: Provide platform module-init macro Javier Martinez Canillas
2021-12-22 8:28 ` [PATCH v3 07/10] drm/imx/dcss: Replace module initialization with DRM helpers Javier Martinez Canillas
2021-12-22 8:28 ` [PATCH v3 08/10] drm/komeda: " Javier Martinez Canillas
2021-12-22 8:28 ` [PATCH v3 09/10] drm/arm/hdlcd: " Javier Martinez Canillas
2021-12-22 8:28 ` [PATCH v3 10/10] drm/malidp: " Javier Martinez Canillas
2022-01-11 8:52 ` [PATCH v3 00/10] drm: Make drivers to honour the nomodeset parameter Thomas Zimmermann
2022-01-19 9:09 ` Javier Martinez Canillas
2022-01-19 18:49 ` Javier Martinez Canillas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211222082831.196562-2-javierm@redhat.com \
--to=javierm@redhat.com \
--cc=airlied@linux.ie \
--cc=corbet@lwn.net \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox