Commit graph

3 commits

Author SHA1 Message Date
FUJITA Tomonori
8d84b32075 rust: device_id: split out index support into a separate trait
Introduce a new trait `RawDeviceIdIndex`, which extends `RawDeviceId`
to provide support for device ID types that include an index or
context field (e.g., `driver_data`). This separates the concerns of
layout compatibility and index-based data embedding, and allows
`RawDeviceId` to be implemented for types that do not contain a
`driver_data` field. Several such structures are defined in
include/linux/mod_devicetable.h.

Refactor `IdArray::new()` into a generic `build()` function, which
takes an optional offset. Based on the presence of `RawDeviceIdIndex`,
index writing is conditionally enabled. A new `new_without_index()`
constructor is also provided for use cases where no index should be
written.

This refactoring is a preparation for enabling the PHY abstractions to
use the RawDeviceId trait.

The changes to acpi.rs and driver.rs were made by Danilo.

Reviewed-by: Trevor Gross <tmgross@umich.edu>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20250711040947.1252162-2-fujita.tomonori@gmail.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2025-07-16 23:38:21 +02:00
Miguel Ojeda
97ba207a99 rust: acpi: remove unneeded cast to clean future Clippy warning
A future Clippy warning, `clippy::as_underscore`, is getting enabled in
parallel in the rust-next tree:

    error: using `as _` conversion
      --> rust/kernel/acpi.rs:25:9
       |
    25 |         self.0.driver_data as _
       |         ^^^^^^^^^^^^^^^^^^^^^^-
       |                               |
       |                               help: consider giving the type explicitly: `usize`

The type is already `ulong`, which nowadays is always `usize`, so the
cast is unneeded. Thus remove it, which in turn will avoid the warning
in the future.

Other abstractions of device tables do not use a cast here either.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Link: https://lore.kernel.org/r/20250701174656.62205-1-ojeda@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-07-03 19:18:59 +02:00
Igor Korotin
a74931eb59 rust: acpi: add acpi::DeviceId abstraction
`acpi::DeviceId` is an abstraction around `struct acpi_device_id`.

Enable drivers to build ACPI device ID tables, to be consumed by the
corresponding bus abstractions, such as platform or I2C.

Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
Link: https://lore.kernel.org/r/20250620152425.285683-1-igor.korotin.linux@gmail.com
[ Always inline DeviceId::new() and use &'static CStr; slightly reword
  commit message. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2025-06-26 23:22:17 +02:00