History

rust: driver: decouple driver private data from driver type

Add a type Data<'bound> associated type to all bus driver traits, decoupling the driver's bus device private data type from the driver struct itself. In the context of adding a 'bound lifetime, making this an associated type has the advantage that it allows us to avoid a driver trait global lifetime and it avoids the need for ForLt for bus device private data; both of which make the subsequent implementation by buses much simpler. All existing drivers and doc examples set type Data = Self to preserve the current behavior.

Danilo Krummrich committed 5 months ago

Commit 7fdffdd1 parent c8a436622 files · +98 −55Browse files

Showing the changes to samples (9 of 22 files). Show all

Unified · Split

9 files
  1. samples/rust/rust_debugfs.rs +1 −0
  2. samples/rust/rust_dma.rs +1 −0
  3. samples/rust/rust_driver_auxiliary.rs +2 −0
  4. samples/rust/rust_driver_i2c.rs +1 −0
  5. samples/rust/rust_driver_pci.rs +1 −0
  6. samples/rust/rust_driver_platform.rs +1 −0
  7. samples/rust/rust_driver_usb.rs +1 −0
  8. samples/rust/rust_i2c_client.rs +1 −0
  9. samples/rust/rust_soc.rs +1 −0
samples/rust/rust_debugfs.rs+1−0
@@ -117,6 +117,7 @@ kernel::acpi_device_table!( · 116 unmodified lines
117 117
118impl platform::Driver for RustDebugFs {118impl platform::Driver for RustDebugFs {
119 type IdInfo = ();119 type IdInfo = ();
120 type Data = Self;
120 const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;121 const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;
121 const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);122 const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
122 123
samples/rust/rust_dma.rs+1−0
@@ -58,6 +58,7 @@ kernel::pci_device_table!( · 57 unmodified lines
58 58
59impl pci::Driver for DmaSampleDriver {59impl pci::Driver for DmaSampleDriver {
60 type IdInfo = ();60 type IdInfo = ();
61 type Data = Self;
61 const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;62 const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
62 63
63 fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {64 fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {
samples/rust/rust_driver_auxiliary.rs+2−0
@@ -31,6 +31,7 @@ kernel::auxiliary_device_table!( · 30 unmodified lines
31 31
32impl auxiliary::Driver for AuxiliaryDriver {32impl auxiliary::Driver for AuxiliaryDriver {
33 type IdInfo = ();33 type IdInfo = ();
34 type Data = Self;
34 35
35 const ID_TABLE: auxiliary::IdTable<Self::IdInfo> = &AUX_TABLE;36 const ID_TABLE: auxiliary::IdTable<Self::IdInfo> = &AUX_TABLE;
36 37
@@ -65,6 +66,7 @@ kernel::pci_device_table!( · 28 unmodified lines
65 66
66impl pci::Driver for ParentDriver {67impl pci::Driver for ParentDriver {
67 type IdInfo = ();68 type IdInfo = ();
69 type Data = Self;
68 70
69 const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;71 const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
70 72
samples/rust/rust_driver_i2c.rs+1−0
@@ -35,6 +35,7 @@ kernel::of_device_table! { · 34 unmodified lines
35 35
36impl i2c::Driver for SampleDriver {36impl i2c::Driver for SampleDriver {
37 type IdInfo = u32;37 type IdInfo = u32;
38 type Data = Self;
38 39
39 const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);40 const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
40 const I2C_ID_TABLE: Option<i2c::IdTable<Self::IdInfo>> = Some(&I2C_TABLE);41 const I2C_ID_TABLE: Option<i2c::IdTable<Self::IdInfo>> = Some(&I2C_TABLE);
samples/rust/rust_driver_pci.rs+1−0
@@ -140,6 +140,7 @@ impl SampleDriver { · 139 unmodified lines
140 140
141impl pci::Driver for SampleDriver {141impl pci::Driver for SampleDriver {
142 type IdInfo = TestIndex;142 type IdInfo = TestIndex;
143 type Data = Self;
143 144
144 const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;145 const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
145 146
samples/rust/rust_driver_platform.rs+1−0
@@ -101,6 +101,7 @@ kernel::acpi_device_table!( · 100 unmodified lines
101 101
102impl platform::Driver for SampleDriver {102impl platform::Driver for SampleDriver {
103 type IdInfo = Info;103 type IdInfo = Info;
104 type Data = Self;
104 const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);105 const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
105 const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);106 const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
106 107
samples/rust/rust_driver_usb.rs+1−0
@@ -26,6 +26,7 @@ kernel::usb_device_table!( · 25 unmodified lines
26 26
27impl usb::Driver for SampleDriver {27impl usb::Driver for SampleDriver {
28 type IdInfo = ();28 type IdInfo = ();
29 type Data = Self;
29 const ID_TABLE: usb::IdTable<Self::IdInfo> = &USB_TABLE;30 const ID_TABLE: usb::IdTable<Self::IdInfo> = &USB_TABLE;
30 31
31 fn probe(32 fn probe(
samples/rust/rust_i2c_client.rs+1−0
@@ -106,6 +106,7 @@ const BOARD_INFO: i2c::I2cBoardInfo = · 105 unmodified lines
106 106
107impl platform::Driver for SampleDriver {107impl platform::Driver for SampleDriver {
108 type IdInfo = ();108 type IdInfo = ();
109 type Data = Self;
109 const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);110 const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
110 const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);111 const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
111 112
samples/rust/rust_soc.rs+1−0
@@ -37,6 +37,7 @@ kernel::acpi_device_table!( · 36 unmodified lines
37 37
38impl platform::Driver for SampleSocDriver {38impl platform::Driver for SampleSocDriver {
39 type IdInfo = ();39 type IdInfo = ();
40 type Data = Self;
40 const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);41 const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
41 const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);42 const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
42 43