Commit Graph

6 Commits

Author SHA1 Message Date
Danilo Krummrich 473b9f3317 rust: pci: fix build failure when CONFIG_PCI_MSI is disabled
When CONFIG_PCI_MSI is disabled pci_alloc_irq_vectors() and
pci_free_irq_vectors() are defined as inline functions and hence require
a Rust helper.

	error[E0425]: cannot find function `pci_alloc_irq_vectors` in crate `bindings`
	    --> rust/kernel/pci/irq.rs:144:23
	     |
	 144 | ...s::pci_alloc_irq_vectors(dev.as_raw(), min_vecs, max_vecs, irq_types.as_raw())
	     |       ^^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `pci_irq_vector`
	     |
	    ::: .../rust/bindings/bindings_helpers_generated.rs:1197:5
	     |
	1197 |     pub fn pci_irq_vector(pdev: *mut pci_dev, nvec: ffi::c_uint) -> ffi::c_int;
	     |     --------------------------------------------------------------------------- similarly named function `pci_irq_vector` defined here

	error[E0425]: cannot find function `pci_free_irq_vectors` in crate `bindings`
	    --> rust/kernel/pci/irq.rs:170:28
	     |
	 170 |         unsafe { bindings::pci_free_irq_vectors(self.dev.as_raw()) };
	     |                            ^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `pci_irq_vector`
	     |
	    ::: .../rust/bindings/bindings_helpers_generated.rs:1197:5
	     |
	1197 |     pub fn pci_irq_vector(pdev: *mut pci_dev, nvec: ffi::c_uint) -> ffi::c_int;
	     |     --------------------------------------------------------------------------- similarly named function `pci_irq_vector` defined here

	error: aborting due to 2 previous errors

Fix this by adding the corresponding helpers.

Fixes: 340ccc9735 ("rust: pci: Allocate and manage PCI interrupt vectors")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202512012238.YgVvRRUx-lkp@intel.com/
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
Link: https://patch.msgid.link/20251202210501.40998-1-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2025-12-04 00:24:47 +13:00
Alistair Popple b6a37d1d46 rust: Add several miscellaneous PCI helpers
Add bindings to obtain a PCI device's resource start address, bus/
device function, revision ID and subsystem device and vendor IDs.

These will be used by the nova-core GPU driver which is currently in
development.

Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Krzysztof Wilczyński <kwilczynski@kernel.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Gary Guo <gary@garyguo.net>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Benno Lossin <lossin@kernel.org>
Cc: Andreas Hindborg <a.hindborg@kernel.org>
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Rafael J. Wysocki <rafael@kernel.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Alexandre Courbot <acourbot@nvidia.com>
Cc: linux-pci@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Alistair Popple <apopple@nvidia.com>
Link: https://lore.kernel.org/r/20250730013417.640593-2-apopple@nvidia.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2025-08-15 20:25:42 +02:00
Daniel Almeida 9b6d4fb980 rust: pci: add irq accessors
These accessors can be used to retrieve a irq::Registration or a
irq::ThreadedRegistration from a pci device. Alternatively, drivers can
retrieve an IrqRequest from a bound PCI device for later use.

These accessors ensure that only valid IRQ lines can ever be registered.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Tested-by: Joel Fernandes <joelagnelf@nvidia.com>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://lore.kernel.org/r/20250811-topics-tyr-request_irq2-v9-6-0485dcd9bcbf@collabora.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2025-08-12 20:33:33 +02:00
Danilo Krummrich 4231712c8e rust: pci: use generic device drvdata accessors
Take advantage of the generic drvdata accessors of the generic Device
type.

While at it, use from_result() instead of match.

Link: https://lore.kernel.org/r/20250621195118.124245-5-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2025-07-09 00:04:33 +02:00
Danilo Krummrich a095d0d1e4 rust: pci: impl TryFrom<&Device> for &pci::Device
Implement TryFrom<&device::Device> for &Device.

This allows us to get a &pci::Device from a generic &Device in a safe
way; the conversion fails if the device' bus type does not match with
the PCI bus type.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/20250321214826.140946-3-dakr@kernel.org
[ Support device context types, use dev_is_pci() helper. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2025-04-19 10:20:16 +02:00
Danilo Krummrich 1bd8b6b2c5 rust: pci: add basic PCI device / driver abstractions
Implement the basic PCI abstractions required to write a basic PCI
driver. This includes the following data structures:

The `pci::Driver` trait represents the interface to the driver and
provides `pci::Driver::probe` for the driver to implement.

The `pci::Device` abstraction represents a `struct pci_dev` and provides
abstractions for common functions, such as `pci::Device::set_master`.

In order to provide the PCI specific parts to a generic
`driver::Registration` the `driver::RegistrationOps` trait is implemented
by `pci::Adapter`.

`pci::DeviceId` implements PCI device IDs based on the generic
`device_id::RawDevceId` abstraction.

Co-developed-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
Link: https://lore.kernel.org/r/20241219170425.12036-10-dakr@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-12-20 17:19:26 +01:00