vhost-device/vhost-device-i2c
Ruoqing He d43fd79bb7 clippy: Fix clippy::precedence
Fix `clippy::precedence` warnings reported by clippy 0.1.85 (4d91de4e48
2025-02-17).

```console
error: operator precedence can trip the unwary
   --> vhost-device-template/src/vhu_foo.rs:152:9
    |
152 | /         1 << VIRTIO_F_VERSION_1
153 | |             | 1 << VIRTIO_F_NOTIFY_ON_EMPTY
154 | |             | 1 << VIRTIO_RING_F_INDIRECT_DESC
155 | |             | 1 << VIRTIO_RING_F_EVENT_IDX
    | |__________________________________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#precedence
    = note: `-D clippy::precedence` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::precedence)]`
help: consider parenthesizing your expression
    |
152 ~         1 << VIRTIO_F_VERSION_1
153 +             | 1 << VIRTIO_F_NOTIFY_ON_EMPTY
154 +             | 1 << VIRTIO_RING_F_INDIRECT_DESC | (1 << VIRTIO_RING_F_EVENT_IDX)
    |
```

Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
2025-03-31 13:45:27 +02:00
..
src clippy: Fix clippy::precedence 2025-03-31 13:45:27 +02:00
Cargo.toml build(deps): bump the rust-vmm group across 2 directories with 1 update 2025-02-17 10:23:08 +02:00
CHANGELOG.md chore: standardize changelogs 2024-07-24 19:37:19 +05:30
LICENSE-APACHE Move all crates to workspace root 2023-10-16 12:03:57 +05:30
LICENSE-BSD-3-Clause Move all crates to workspace root 2023-10-16 12:03:57 +05:30
README.md i2c: Support for both bus name and bus number 2024-03-20 16:13:54 +05:30

vhost-device-i2c - I2C emulation backend daemon

Description

This program is a vhost-user backend that emulates a VirtIO I2C bus. This program takes the layout of the i2c bus and its devices on the host OS and then talks to them via the /dev/i2c-X interface when a request comes from the guest OS for an I2C or SMBUS device.

This program is tested with QEMU's -device vhost-user-i2c-pci but should work with any virtual machine monitor (VMM) that supports vhost-user. See the Examples section below.

Synopsis

vhost-device-i2c [OPTIONS]

Options

.. program:: vhost-device-i2c

.. option:: -h, --help

Print help.

.. option:: -s, --socket-path=PATH

Location of vhost-user Unix domain sockets, this path will be suffixed with 0,1,2..socket_count-1.

.. option:: -c, --socket-count=INT

Number of guests (sockets) to attach to, default set to 1.

.. option:: -l, --device-list=I2C-DEVICES

I2c device list at the host OS can be in two different format, name and number:

  • format by name: <bus-name>:<client_addr>[:<client_addr>],[<bus-name>:<client_addr>[:<client_addr>]]
      Example: --device-list "i915 gmbus dpd:32:21,DPDDC-D:10:23"

Here, bus-name: is adatper's name. e.g. value of /sys/bus/i2c/devices/i2c-0/name. client_addr (decimal): address for client device, 32 == 0x20.

  • format by number: <bus>:<client_addr>[:<client_addr>],[<bus>:<client_addr>[:<client_addr>]]
      Example: --device-list "2:32:21,3:10:23"

Here, bus (decimal): adatper bus number. e.g. 2 for /dev/i2c-2, 3 for /dev/i2c-3. client_addr (decimal): address for client device, 32 == 0x20.

Examples

The daemon should be started first:

::

host# vhost-device-i2c --socket-path=vi2c.sock --socket-count=1 --device-list "i915 gmbus dpd:32"

host# vhost-device-i2c --socket-path=vi2c.sock --socket-count=1 --device-list "0:32"

The QEMU invocation needs to create a chardev socket the device can use to communicate as well as share the guests memory over a memfd.

::

host# qemu-system
-chardev socket,path=vi2c.sock,id=vi2c
-device vhost-user-i2c-pci,chardev=vi2c,id=i2c
-m 4096
-object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on
-numa node,memdev=mem
...

License

This project is licensed under either of