Commit Graph

15 Commits

Author SHA1 Message Date
Milan Zamazal
07cbe73dc8 scmi: Improve output on backend configuration error
Print a properly formatted error to both the log and terminal.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
0261d315ac scmi: Improve command line processing
When a device help is requested with `-d help', the socket argument is
still required.  This patch:

- replaces `-d help' with --help-devices;
- stops requiring the socket argument in such a case;
- prints help in case of command line parsing errors.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
847b3f44a6 scmi: Add source code docstrings
Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
458f168639 scmi: Add support for industrial I/O devices
Industrial I/O (IIO) devices are present in /sys/bus/iio/devices/ on
Linux.  This patch makes them accessible to the guests via the sensor
SCMI protocol.

The implementation no way covers all the possible IIO devices.  It
supports some basic stuff, other sensors can be added as needed.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
c1637e94b8 scmi: Use new_device for ScmiDevice constructors
Instead of `new', which should be reserved for direct constructors.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
789288c372 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>
2023-09-04 16:15:33 +01:00
Milan Zamazal
cbb0449d43 scmi: Refactor unit handling
Make unit handling better SCMI compliant.  Let's distinguish between
scalar sensors and axis sensors and report the units in the
appropriate SCMI commands.  Also, let's change the unit type to u8 to
correspond to the number of unit bits in SCMI.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
58ddb26d5b scmi: Use separate modules for device implementations
For a better readability once we start adding more devices.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
ca8f181bcd scmi: Refactor device specification and creation
Making the device configuration polymorphic requires the device struct
to exist before the device parameters are checked and assigned to the
struct fields.  Which means wrapping the struct fields by Option
unnecessarily or introducing other data confusion.

Let's extract the device configuration from traits to plain functions
in order to keep the device struct's unencumbered.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
73c536df2e scmi: Provide help for devices
Writing `--device help' on the command line will list all the
available devices and their parameters.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
e0fdfa4c38 scmi: Refactor devices.rs for sensor code reuse
Different sensors will have similar handling.  Let’s extract generic
parts from FakeSensor implementation into a reusable code, within the
limits of Rust.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
3d1cc5b370 scmi: Add a command line option for defining devices
The code already contains support for creating devices that can serve
as SCMI-accessible sensors and a sample fake devices.  But to actually
use the device, the code must be modified.

This patch adds a command line option to define the devices on start.
The format of the option value is in the QEMU style:
DEVICE,PROPERTY=VALUE,…

For example:

  --device fake,name=fake1 fake,name=fake2

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
bc7faf7685 scmi: Add sensor management protocol
This patch implements the necessary parts of the SCMI sensor
management protocol, required either by the SCMI standard or by Linux
VIRTIO SCMI drivers to function correctly.  A part of this
implementation is a fake sensor device, which is useful for both unit
testing here and a testing with a real guest OS.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
5b0b8c3753 scmi: Implement SCMI base protocol
Implementation of the mandatory parts of the SCMI base protocol.  This
allows the daemon to communicate with the guest SCMI VIRTIO device,
although not yet providing any useful functionality.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
9513ed841c scmi: Initial skeleton
This patch adds support for a SCMI vhost-user device.  It implements
the basic skeleton of the vhost-user daemon and of SCMI processing.
It doesn’t provide any real functionality yet, adding it will be the
subject of followup patches.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00