pub trait VirtIODeviceDriver {
// Required methods
fn negotiate_features(&self, offered_features: u64) -> Option<u64>;
fn device_type(&self) -> VirtIODeviceType;
// Provided methods
fn pre_device_initialization(&self) -> Result<(), ErrorCode> { ... }
fn device_initialized(&self) -> Result<(), ErrorCode> { ... }
}
Expand description
VirtIO Device Driver.
This trait is to be implemented by drivers for exposed VirtIO devices, using
the transports provided in crate::transports
and queues in
crate::queues
to communicate with VirtIO devices.
Required Methods§
Sourcefn negotiate_features(&self, offered_features: u64) -> Option<u64>
fn negotiate_features(&self, offered_features: u64) -> Option<u64>
VirtIO feature negotiation.
This function is passed all driver-specific feature bits which the
device exposes. Based on this function, the driver can select which
features to enable through the return value of this function. This
function is executed through the VirtIO transport, potentially before
the device is initialized. As such, implementations of this function
should be pure and only depend on the offered_features
input
parameter.
Sourcefn device_type(&self) -> VirtIODeviceType
fn device_type(&self) -> VirtIODeviceType
VirtIO device type which the driver supports.
This function must return the VirtIO device type that the driver is able to drive. Implementations of this function must be pure and return a constant value.
Provided Methods§
Sourcefn pre_device_initialization(&self) -> Result<(), ErrorCode>
fn pre_device_initialization(&self) -> Result<(), ErrorCode>
Hook called before the transport indicates DRIVER_OK
to the device.
Because this trait must be object safe, a device cannot convey arbitrary
errors through this interface. When this function returns an error, the
transport will indicate FAILED
to the device and return the error to
the caller of
VirtIOTransport::initialize
.
The driver can store a more elaborate error internally and expose it
through a custom interface.
A default implementation of this function is provided which does nothing
and returns Ok(())
.
Sourcefn device_initialized(&self) -> Result<(), ErrorCode>
fn device_initialized(&self) -> Result<(), ErrorCode>
Hook called after the transport indicated DRIVER_OK
to the device.
Because this trait must be object safe, a device cannot convey arbitrary
errors through this interface. When this function returns an error, the
transport will NOT indicate FAILED
to the device, but return the
error to the caller of
VirtIOTransport::initialize
.
The driver can store a more elaborate error internally and expose it
through a custom interface. The driver remains responsible for any
deinitialization of the device as a result of this error.
A default implementation of this function is provided which does nothing
and returns Ok(())
.