Discussion of the implementations of VIRTIO specification
 help / color / mirror / Atom feed
From: Jie Deng <jie.deng@intel.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: virtio-comment@lists.oasis-open.org,
	virtio-dev@lists.oasis-open.org, mst@redhat.com,
	cohuck@redhat.com, pbonzini@redhat.com, kraxel@redhat.com,
	wsa+renesas@sang-engineering.com,
	andriy.shevchenko@linux.intel.com, conghui.chen@intel.com,
	yu1.wang@intel.com, shuo.a.liu@intel.com
Subject: Re: [virtio-comment] [PATCH v5] virtio-i2c: add the device specification
Date: Thu, 17 Dec 2020 15:08:07 +0800	[thread overview]
Message-ID: <b59c78ee-1f25-e32b-fc22-697b92084ae0@intel.com> (raw)
In-Reply-To: <20201216155218.GA720702@stefanha-x1.localdomain>

[-- Attachment #1: Type: text/plain, Size: 3448 bytes --]


On 2020/12/16 23:52, Stefan Hajnoczi wrote:
> On Wed, Nov 25, 2020 at 01:55:18PM +0800, Jie Deng wrote:
>> diff --git a/virtio-i2c.tex b/virtio-i2c.tex
>> new file mode 100644
>> index 0000000..fdb0050
>> --- /dev/null
>> +++ b/virtio-i2c.tex
>> @@ -0,0 +1,139 @@
>> +\section{I2C Adapter Device}\label{sec:Device Types / I2C Adapter Device}
>> +
>> +virtio-i2c is a virtual I2C adapter device. It provides a way to flexibly
>> +organize and use the host I2C slave devices from the guest. By attaching
>> +the host ACPI I2C slave nodes to the virtual I2C adapter device, the guest can
>> +communicate with them without changing or adding extra drivers for these
>> +slave I2C devices.
> Is there a way to identify I2C busses if more than one virtio-i2c device
> is present? For example, imagine a host with 2 I2C busses. How does the
> guest know which virtio-i2c device connects to which host bus?
This virtio-i2c is a master device. The slave devices attached to it can 
be configured
by the backend in the host. These slave devices can be under different 
host I2C master devices.
The guest will see this virtio-i2c master device and its slave devices.

There is a example about the backend which shows how it works

https://projectacrn.github.io/latest/developer-guides/hld/virtio-i2c.html?highlight=i2c
https://github.com/projectacrn/acrn-hypervisor/blob/master/devicemodel/hw/pci/virtio/virtio_i2c.c
>
>> +\begin{lstlisting}
>> +struct virtio_i2c_req {
>> +        le16 addr;
>> +        le32 flags;
> What is the memory layout?
>
> 1. 0x0 addr, 0x2 flags
>
> or
>
> 2. 0x0 addr, 0x4 flags
>
> This is unclear to me. I don't see a general statement in the spec about
> struct field alignment/padding and no details in this new spec change.

Both are OK to me. I used to use "packed" but Michael said there was no 
need to pack it.

https://lkml.org/lkml/2020/9/3/339

So you prefer it to be clear ?

>> +        le16 written;
>> +        le16 read;
>> +        u8 write_buf[];
>> +        u8 read_buf[];
>> +        u8 status;
>> +};
>> +\end{lstlisting}
>> +
>> +The \field{addr} of the request is the address of the I2C slave device.
> https://en.wikipedia.org/wiki/I2c#Addressing_structure suggests there
> are at least 7-bit and 10-bit addressing schemes in I2C. How does this
> map to the little-endian 16-bit addr field?

This field maps to the kernel struct "i2c_msg.addr".

struct virtio_i2c_req  *vmsg;
struct i2c_msg *msg;

vmsg->addr  = cpu_to_le16(msg->addr);

The field in the request can be seen as host byte order
while the link can be seen as the I2C network byte order.
The host driver may take care thisconversion.

>> +The \field{flags} of the request is currently reserved as zero for future
>> +feature extensibility.
>> +
>> +The \field{written} of the request is the number of data bytes in the \field{write_buf}
>> +being written to the I2C slave address.
> This field seems redundant since the device can determine the size of
> write_buf implicitly from the total out buffer size. virtio-blk takes
> this approach.
The read/write are the actual number of data bytes being read from or 
written to the device
which is not determined by the device. So I don't think it is redundant.
>> +The \field{read} of the request is the number of data bytes in the \field{read_buf}
>> +being read from the I2C slave address.
> Same here. virtio-blk doesn't use an explicit read size field because
> the device can determine it.

[-- Attachment #2: Type: text/html, Size: 5964 bytes --]

  reply	other threads:[~2020-12-17  7:08 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-25  5:55 [virtio-comment] [PATCH v5] virtio-i2c: add the device specification Jie Deng
2020-11-25 12:52 ` Andy Shevchenko
2020-11-26  2:58   ` [virtio-comment] " Jie Deng
2020-12-08  1:08 ` Jie Deng
2020-12-16 15:52 ` [virtio-comment] " Stefan Hajnoczi
2020-12-17  7:08   ` Jie Deng [this message]
2020-12-17  8:00     ` Michael S. Tsirkin
2020-12-17 10:26       ` Stefan Hajnoczi
2020-12-18  2:06         ` Jie Deng
2020-12-19 19:05           ` Michael S. Tsirkin
2020-12-22  6:11             ` Jie Deng
2020-12-22 11:29               ` Cornelia Huck
2020-12-22 22:31                 ` Michael S. Tsirkin
2020-12-24  8:15                   ` Jie Deng
2020-12-17 10:43     ` Stefan Hajnoczi
2020-12-16 17:38 ` Cornelia Huck
2020-12-16 19:55   ` Michael S. Tsirkin
2020-12-17  8:38     ` Jie Deng
2020-12-17 19:43       ` Michael S. Tsirkin
2020-12-18  1:21         ` Jie Deng
2020-12-17  7:29   ` Jie Deng
2020-12-17  7:56     ` Cornelia Huck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b59c78ee-1f25-e32b-fc22-697b92084ae0@intel.com \
    --to=jie.deng@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=cohuck@redhat.com \
    --cc=conghui.chen@intel.com \
    --cc=kraxel@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=shuo.a.liu@intel.com \
    --cc=stefanha@redhat.com \
    --cc=virtio-comment@lists.oasis-open.org \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=wsa+renesas@sang-engineering.com \
    --cc=yu1.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox