rust: driver: add DriverData type to the DriverLayout trait

Add an associated type DriverData to the DriverLayout trait indicating
the type of the driver's device private data.

Acked-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Igor Korotin <igor.korotin.linux@gmail.com>
Link: https://patch.msgid.link/20260107103511.570525-6-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

+14
+2
rust/kernel/auxiliary.rs
··· 25 25 26 26 // SAFETY: 27 27 // - `bindings::auxiliary_driver` is a C type declared as `repr(C)`. 28 + // - `T` is the type of the driver's device private data. 28 29 // - `struct auxiliary_driver` embeds a `struct device_driver`. 29 30 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 30 31 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 31 32 type DriverType = bindings::auxiliary_driver; 33 + type DriverData = T; 32 34 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 33 35 } 34 36
+4
rust/kernel/driver.rs
··· 108 108 /// 109 109 /// Implementors must guarantee that: 110 110 /// - `DriverType` is `repr(C)`, 111 + /// - `DriverData` is the type of the driver's device private data. 111 112 /// - `DriverType` embeds a valid `struct device_driver` at byte offset `DEVICE_DRIVER_OFFSET`. 112 113 pub unsafe trait DriverLayout { 113 114 /// The specific driver type embedding a `struct device_driver`. 114 115 type DriverType: Default; 116 + 117 + /// The type of the driver's device private data. 118 + type DriverData; 115 119 116 120 /// Byte offset of the embedded `struct device_driver` within `DriverType`. 117 121 ///
+2
rust/kernel/i2c.rs
··· 94 94 95 95 // SAFETY: 96 96 // - `bindings::i2c_driver` is a C type declared as `repr(C)`. 97 + // - `T` is the type of the driver's device private data. 97 98 // - `struct i2c_driver` embeds a `struct device_driver`. 98 99 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 99 100 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 100 101 type DriverType = bindings::i2c_driver; 102 + type DriverData = T; 101 103 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 102 104 } 103 105
+2
rust/kernel/pci.rs
··· 52 52 53 53 // SAFETY: 54 54 // - `bindings::pci_driver` is a C type declared as `repr(C)`. 55 + // - `T` is the type of the driver's device private data. 55 56 // - `struct pci_driver` embeds a `struct device_driver`. 56 57 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 57 58 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 58 59 type DriverType = bindings::pci_driver; 60 + type DriverData = T; 59 61 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 60 62 } 61 63
+2
rust/kernel/platform.rs
··· 28 28 29 29 // SAFETY: 30 30 // - `bindings::platform_driver` is a C type declared as `repr(C)`. 31 + // - `T` is the type of the driver's device private data. 31 32 // - `struct platform_driver` embeds a `struct device_driver`. 32 33 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 33 34 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 34 35 type DriverType = bindings::platform_driver; 36 + type DriverData = T; 35 37 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 36 38 } 37 39
+2
rust/kernel/usb.rs
··· 29 29 30 30 // SAFETY: 31 31 // - `bindings::usb_driver` is a C type declared as `repr(C)`. 32 + // - `T` is the type of the driver's device private data. 32 33 // - `struct usb_driver` embeds a `struct device_driver`. 33 34 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 34 35 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 35 36 type DriverType = bindings::usb_driver; 37 + type DriverData = T; 36 38 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 37 39 } 38 40