mirror of
https://github.com/rust-vmm/vhost-device.git
synced 2026-01-08 12:38:21 +00:00
scmi: Add sensor device initialization function
Implementation accessing real sensors will need to set up the device instance. Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
This commit is contained in:
parent
cbb0449d43
commit
789288c372
@ -191,6 +191,10 @@ pub trait SensorT: Send {
|
||||
fn sensor(&self) -> &Sensor;
|
||||
fn sensor_mut(&mut self) -> &mut Sensor;
|
||||
|
||||
fn initialize(&mut self) -> Result<(), DeviceError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn protocol(&self) -> ProtocolId {
|
||||
SENSOR_PROTOCOL_ID
|
||||
}
|
||||
@ -328,6 +332,10 @@ pub trait SensorT: Send {
|
||||
pub struct SensorDevice(pub(crate) Box<dyn SensorT>);
|
||||
|
||||
impl ScmiDevice for SensorDevice {
|
||||
fn initialize(&mut self) -> Result<(), DeviceError> {
|
||||
self.0.initialize()
|
||||
}
|
||||
|
||||
fn protocol(&self) -> ProtocolId {
|
||||
self.0.protocol()
|
||||
}
|
||||
|
||||
@ -11,6 +11,8 @@ use itertools::Itertools;
|
||||
use log::{debug, error, info};
|
||||
use thiserror::Error as ThisError;
|
||||
|
||||
use crate::devices::common::DeviceError;
|
||||
|
||||
pub type MessageHeader = u32;
|
||||
|
||||
pub const MAX_SIMPLE_STRING_LENGTH: usize = 16; // incl. NULL terminator
|
||||
@ -484,6 +486,7 @@ pub enum ScmiDeviceError {
|
||||
}
|
||||
|
||||
pub trait ScmiDevice: Send {
|
||||
fn initialize(&mut self) -> Result<(), DeviceError>;
|
||||
fn protocol(&self) -> ProtocolId;
|
||||
fn handle(
|
||||
&mut self,
|
||||
|
||||
@ -103,7 +103,15 @@ impl VuScmiBackend {
|
||||
}
|
||||
match device_mapping.get(name.as_str()) {
|
||||
Some(specification) => match (specification.constructor)(properties) {
|
||||
Ok(device) => handler.register_device(device),
|
||||
Ok(mut device) => {
|
||||
if let Err(error) = device.initialize() {
|
||||
return Result::Err(VuScmiError::DeviceConfigurationError(
|
||||
name.clone(),
|
||||
error,
|
||||
));
|
||||
}
|
||||
handler.register_device(device);
|
||||
}
|
||||
Err(error) => {
|
||||
return Result::Err(VuScmiError::DeviceConfigurationError(
|
||||
name.clone(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user