Skip to content

Device: generic accessors for drvdata + Driver::unbind()

Danilo Krummrich linux-pci lkml rust-for-linux 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest8 patches 18 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8rust: device: introduce device::Internalrust/kernel/device.rs+14 -04 replies
2/8rust: device: add drvdata accessorsrust/helpers/device.c rust/kernel/device.rs+52 -18 replies
3/8rust: platform: use generic device drvdata accessorsrust/helpers/platform.c rust/kernel/platform.rs+17 -290 replies
4/8rust: pci: use generic device drvdata accessorsrust/helpers/pci.c rust/kernel/pci.rs+14 -271 reply
5/8rust: auxiliary: use generic device drvdata accessorsrust/helpers/auxiliary.c rust/kernel/auxiliary.rs+15 -300 replies
6/8rust: platform: implement Driver::unbind()rust/kernel/platform.rs+17 -10 replies
7/8rust: pci: implement Driver::unbind()rust/kernel/pci.rs+17 -10 replies
8/8samples: rust: pci: reset pci-testdev in unbind()samples/rust/rust_driver_pci.rs+10 -10 replies

Reviews trailers per patch

1 of 8 patches has a Reviewed-by or Acked-by.

PatchBenno Lossin
1/8
2/8A-b
3/8
4/8
5/8
6/8
7/8
8/8

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/8] Device: generic accessors for drvdata + Driver::unbind()

This patch series consists of the following three parts.

1. Introduce the 'Internal' device context (semantically identical to the 'Core' device context), but only accessible for bus abstractions.

2. Introduce generic accessors for a device's driver_data pointer. Those are implemented for the 'Internal' device context only, in order to only enable bus abstractions to mess with the driver_data pointer of struct device.

3. Implement the Driver::unbind() callback (details below).

Driver::unbind()
----------------

Currently, there's really only one core callback for drivers, which is probe().

Now, this isn't entirely true, since there is also the drop() callback of the driver type (serving as the driver's private data), which is returned by probe() and is dropped in remove().

On the C side remove() mainly serves two purposes:

(1) Tear down the device that is operated by the driver, e.g. call bus specific functions, write I/O memory to reset the device, etc.

(2) Release the resources that have been allocated by a driver for a specific device.

The drop() callback mentioned above is intended to cover (2) as the Rust idiomatic way.

However, it is partially insufficient and inefficient to cover (1) properly, since drop() can't be called with additional arguments, such as the reference to the corresponding device that has the correct device context, i.e. the Core device context.

This makes it inefficient (but not impossible) to access device resources, e.g. to write device registers, and impossible to call device methods, which are only accessible under the Core device context.

In order to solve this, add an additional callback for (1), which we call unbind().

The reason for calling it unbind() is that, unlike remove(), it is *only* meant to be used to perform teardown operations on the device (1), but *not* to release resources (2).

Danilo Krummrich (8):
rust: device: introduce device::Internal
rust: device: add drvdata accessors
rust: platform: use generic device drvdata accessors
rust: pci: use generic device drvdata accessors
rust: auxiliary: use generic device drvdata accessors
rust: platform: implement Driver::unbind()
rust: pci: implement Driver::unbind()
samples: rust: pci: reset pci-testdev in unbind()

 rust/helpers/auxiliary.c        | 10 ------
 rust/helpers/device.c           | 10 ++++++
 rust/helpers/pci.c              | 10 ------
 rust/helpers/platform.c         | 10 ------
 rust/kernel/auxiliary.rs        | 35 +++++++++-----------
 rust/kernel/device.rs           | 57 ++++++++++++++++++++++++++++++++-
 rust/kernel/pci.rs              | 47 +++++++++++++++++----------
 rust/kernel/platform.rs         | 52 +++++++++++++++++++-----------
 samples/rust/rust_driver_pci.rs | 11 ++++++-
 9 files changed, 154 insertions(+), 88 deletions(-)

base-commit: b29929b819f35503024c6a7e6ad442f6e36c68a0

Signature · 1 line
2.49.0