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. 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 | 23 +++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/drivers/gpu/nova-core/Kconfig b/drivers/gpu/nova-core/Kconfig index 2e11e46c99c7..058742d50692 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. + + 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 NVIDIA GPUs + instead. + + nova-core is work in progress and may not be functional, so this + is intended for nova developers and testers only. When enabled, + nouveau must not bind to the same (GSP-capable) GPUs, i.e. + CONFIG_DRM_NOUVEAU_BIND_GSP=N or nouveau.bind_gsp=0 is required. + Otherwise both drivers compete for the same devices and + whichever is loaded first wins. + + If unsure, say N. diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs index d6bc972d47c7..e89967ef0cd5 100644 --- a/drivers/gpu/nova-core/driver.rs +++ b/drivers/gpu/nova-core/driver.rs @@ -105,6 +105,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..483e5c1d427b 100644 --- a/drivers/gpu/nova-core/nova_core.rs +++ b/drivers/gpu/nova-core/nova_core.rs @@ -68,6 +68,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<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 +116,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
