Skip to main content

Driver

Trait Driver 

Source
pub trait Driver {
    type IdInfo: 'static;
    type Data<'bound>: Send + 'bound;

    const OF_ID_TABLE: Option<IdTable<Self::IdInfo>> = None;
    const ACPI_ID_TABLE: Option<IdTable<Self::IdInfo>> = None;

    // Required method
    fn probe<'bound>(
        dev: &'bound Device<Core<'_>>,
        id_info: Option<&'bound Self::IdInfo>,
    ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound;

    // Provided method
    fn unbind<'bound>(
        dev: &'bound Device<Core<'_>>,
        this: Pin<&Self::Data<'bound>>,
    ) { ... }
}
Expand description

The platform driver trait.

Drivers must implement this trait in order to get a platform driver registered.

§Examples

 struct MyDriver;

 kernel::of_device_table!(
     OF_TABLE,
     MODULE_OF_TABLE,
     <MyDriver as platform::Driver>::IdInfo,
     [
         (of::DeviceId::new(c"test,device"), ())
     ]
 );

 kernel::acpi_device_table!(
     ACPI_TABLE,
     MODULE_ACPI_TABLE,
     <MyDriver as platform::Driver>::IdInfo,
     [
         (acpi::DeviceId::new(c"LNUXBEEF"), ())
     ]
 );

 impl platform::Driver for MyDriver {
     type IdInfo = ();
     type Data<'bound> = Self;
     const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
     const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);

     fn probe<'bound>(
         _pdev: &'bound platform::Device<Core<'_>>,
         _id_info: Option<&'bound Self::IdInfo>,
     ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
         Err(ENODEV)
     }
 }

Provided Associated Constants§

Source

const OF_ID_TABLE: Option<IdTable<Self::IdInfo>> = None

The table of OF device ids supported by the driver.

Source

const ACPI_ID_TABLE: Option<IdTable<Self::IdInfo>> = None

The table of ACPI device ids supported by the driver.

Required Associated Types§

Source

type IdInfo: 'static

The type holding driver private data about each device id supported by the driver.

Source

type Data<'bound>: Send + 'bound

The type of the driver’s bus device private data.

Required Methods§

Source

fn probe<'bound>( dev: &'bound Device<Core<'_>>, id_info: Option<&'bound Self::IdInfo>, ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound

Platform driver probe.

Called when a new platform device is added or discovered. Implementers should attempt to initialize the device here.

Provided Methods§

Source

fn unbind<'bound>(dev: &'bound Device<Core<'_>>, this: Pin<&Self::Data<'bound>>)

Platform driver unbind.

Called when a Device is unbound from its bound Driver. Implementing this callback is optional.

This callback serves as a place for drivers to perform teardown operations that require a &Device<Core> or &Device<Bound> reference. For instance, drivers may try to perform I/O operations to gracefully tear down the device.

Otherwise, release operations for driver resources should be performed in Drop.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§