From: Dave Airlie <[email protected]>

nova-core currently binds to every NVIDIA GPU it supports
(GSP-capable, Turing and later GPUs), competing with nouveau for the
same devices.

Add the NOVA_CORE_BIND_GSP Kconfig option (default n) and a bind_gsp
module parameter, defaulting to the Kconfig value and able to override
it in both directions. Unless one of them requests binding, probe()
rejects the GPU with -ENODEV and leaves the device to other drivers,
such as nouveau. The PCI driver still registers, so module autoloading
via modalias keeps working when binding is disabled.

The option is also the single switch deciding which driver claims
GSP-capable GPUs by default: nouveau's bind_gsp parameter (previous
patch) defaults to its inverse, so saying Y here makes nova-core the
default driver for GSP-capable GPUs without any additional nouveau
configuration. Configurations that do not build nova-core at all are
unaffected.

As nova-core is work in progress, the default is to not bind at all.
Developers can enable binding with CONFIG_NOVA_CORE_BIND_GSP=y, or
nova-core.bind_gsp=1 on the kernel command line.

Signed-off-by: Dave Airlie <[email protected]>
---
 drivers/gpu/nova-core/Kconfig      | 21 +++++++++++++++++++++
 drivers/gpu/nova-core/driver.rs    |  4 ++++
 drivers/gpu/nova-core/nova_core.rs | 24 ++++++++++++++++++++++++
 3 files changed, 49 insertions(+)

diff --git a/drivers/gpu/nova-core/Kconfig b/drivers/gpu/nova-core/Kconfig
index 2e11e46c99c7..a6d8797d245c 100644
--- a/drivers/gpu/nova-core/Kconfig
+++ b/drivers/gpu/nova-core/Kconfig
@@ -30,3 +30,24 @@ config NOVA_CORE_SELFTESTS
          logs its failure and lets the probe continue.
 
          If unsure, say N.
+
+config NOVA_CORE_BIND_GSP
+       bool "Make nova-core the default driver for GSP-capable GPUs"
+       depends on NOVA_CORE
+       default n
+       help
+         Make nova-core bind to all NVIDIA GPUs it supports by default,
+         and have nouveau leave GSP-capable (Turing and later) GPUs to
+         nova-core instead of claiming them itself. Pre-Turing GPUs are
+         always left to nouveau.
+
+         By default nova-core does not bind to any GPU and leaves NVIDIA
+         GPUs to other drivers, such as nouveau. Say Y here, or boot with
+         nova-core.bind_gsp=1, to make nova-core claim GSP-capable GPUs
+         instead. For a single boot, nouveau.bind_gsp=1 makes nouveau
+         claim them again.
+
+         nova-core is work in progress and may not be functional, so this
+         is intended for nova developers and testers only.
+
+         If unsure, say N.
diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs
index bea1b1b0844c..89f53944597c 100644
--- a/drivers/gpu/nova-core/driver.rs
+++ b/drivers/gpu/nova-core/driver.rs
@@ -106,6 +106,10 @@ fn probe<'bound>(
         dev_dbg!(pdev, "Probe Nova Core GPU driver.\n");
 
         try_pin_init!(NovaCore {
+            _: {
+                crate::NovaCoreModule::check_bind_allowed(pdev)?;
+            },
+
             _: {
                 pdev.enable_device_mem()?;
                 pdev.set_master();
diff --git a/drivers/gpu/nova-core/nova_core.rs 
b/drivers/gpu/nova-core/nova_core.rs
index 84f777844592..0aaf4f6c07f8 100644
--- a/drivers/gpu/nova-core/nova_core.rs
+++ b/drivers/gpu/nova-core/nova_core.rs
@@ -4,6 +4,7 @@
 
 use kernel::{
     device,
+    device::Core,
     driver::Registration,
     pci,
     prelude::*,
@@ -68,6 +69,25 @@ pub(crate) fn debugfs_data<'a>(_dev: &'a 
device::Device<device::Bound>) -> &'a D
     }
 }
 
+impl NovaCoreModule {
+    /// Check whether nova-core is allowed to bind to GPUs.
+    ///
+    /// Binding needs to be requested explicitly, either through the
+    /// NOVA_CORE_BIND_GSP Kconfig option or the `bind_gsp` module parameter.
+    /// Otherwise, NVIDIA GPUs are left to other drivers, such as nouveau.
+    pub(crate) fn check_bind_allowed(pdev: &pci::Device<Core<'_>>) -> Result {
+        if crate::module_parameters::bind_gsp.value() {
+            return Ok(());
+        }
+
+        dev_info!(
+            pdev,
+            "Not binding to GPU; enable with CONFIG_NOVA_CORE_BIND_GSP=y or 
nova-core.bind_gsp=1\n"
+        );
+        Err(ENODEV)
+    }
+}
+
 impl InPlaceModule for NovaCoreModule {
     fn init(module: &'static kernel::ThisModule) -> impl PinInit<Self, Error> {
         try_pin_init!(Self {
@@ -97,6 +117,10 @@ fn init(module: &'static kernel::ThisModule) -> impl 
PinInit<Self, Error> {
             default: false,
             description: "Keep the GSP-RM log buffers in debugfs after their 
GPU is unbound",
         },
+        bind_gsp: bool {
+            default: cfg!(CONFIG_NOVA_CORE_BIND_GSP),
+            description: "Bind to GSP-capable GPUs, making nova-core the 
default NVIDIA driver",
+        },
     },
 }
 

-- 
2.56.1


Reply via email to