qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Virtual I2C adapter and I2C external simulator


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] Virtual I2C adapter and I2C external simulator
Date: Fri, 14 Jun 2019 10:31:24 +0100
User-agent: Mutt/1.11.4 (2019-03-13)

On Thu, Jun 13, 2019 at 10:53:16AM -0700, Rahul Govind wrote:
> Hi Everyone,
> 
> I'm working on a project that involves building on top of existing QEMU
> work, and I'm trying to virtualize I2C devices that are shared between
> multiple VMs. I've been reading QEMU documentation and source code to get a
> better idea of how to add something like this to QEMU (since it doesn't
> look like something similar is already present) but I'm not sure how to
> proceed. I do have a few ideas and I would be grateful if anyone could give
> me feedback on them or suggestions for alternative solutions.
> 
> More specifically, I wish to virtualize a couple of devices that sit on the
> I2C bus. However, directly virtualizing the devices doesn't seem feasible
> since there are many other devices like multiplexers on the way to these
> devices. Also, what we need is to handle is just reads/write/ioctls on
> /dev/i2c-N.
> 
> I was wondering if there is a way to create a device that
> - 1) Emulates an I2C adapter, say /dev/i2c-0.
> - 2) Handles any reads/writes/ioctls sent to /dev/i2c-0, reformats any
> ioctls as IO, and then sends this to a simulator on the host.
> 
> This approach is just based on the ipmi interface and ipmi-bmc-extern
> device already present in QEMU, where ipmi-bmc-extern can communicate
> through a chardev with a simulator running on the host. Having a simulator
> on the host would be nice to have since it lets us write the simulator in a
> higher level language, and as previously mentioned, we have a few cases
> where multiple VMs share the same I2C device. However, I'm not sure if this
> even makes sense in the case of I2C.
> 
> If this approach doesn't make sense, what method would you recommend to
> have virtual I2C devices which are shared between multiple VMs?
> 
> Any suggestions or guidance is much appreciated!

Hi Rahul,
A good rule of thumb is that if it's possible in real hardware then it
can be emulated.  So in this case the question is whether an I2C device
can be accessed by multiple bus masters.  The answer seems to be yes:
https://www.i2c-bus.org/multimaster/

Ernest recently posted patches to add a chardev to QEMU that
reads/writes to a host /dev/i2c-0 device.  What you are describing is a
little different but related.

In theory it is possible to define an I2C-over-socket protocol (for
example a UNIX Domain Socket) so that an external process can simulate
an I2C device.  QEMU will emulate the I2C controller and forward bus
transactions to the external process.

If you want multi-master I2C then the external process needs to accept
multiple connections so that more than one QEMU can connect at
simultaneously.

Stefan

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]