From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WEL9g-0000ST-IU for qemu-devel@nongnu.org; Fri, 14 Feb 2014 10:58:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WEL9Y-0000GD-4t for qemu-devel@nongnu.org; Fri, 14 Feb 2014 10:58:20 -0500 Received: from mail-qc0-x22f.google.com ([2607:f8b0:400d:c01::22f]:46893) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WEL9Y-0000G4-0d for qemu-devel@nongnu.org; Fri, 14 Feb 2014 10:58:12 -0500 Received: by mail-qc0-f175.google.com with SMTP id x13so20107918qcv.20 for ; Fri, 14 Feb 2014 07:58:11 -0800 (PST) Sender: Paolo Bonzini Message-ID: <52FE3D0E.8070904@redhat.com> Date: Fri, 14 Feb 2014 16:58:06 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] Trying to write a new device / virtio-i2c ? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex David , qemu-devel@nongnu.org Il 13/02/2014 14:26, Alex David ha scritto: > After reading code, documentation and available things, I've been trying > to write something like a "virtio-i2c" : I wrote a virtio-i2c module for > my kernel (I used some examples from virtio-pci and virtio-console), it > seems that it created a "i2c-1" device in /dev, > > My device that I launch with QEMU (-chardev > socket,path=/tmp/test0,server,nowait,id=bob -device > virtio-i2c,chardev=bob) doesn't seem to be recognized by the kernel > driver : my probe function doesn't run. i2c is a bus, not directly a device. Do you want to pass an entire adapter down to the guest? Or just a slave? QEMU has i2c emulation but it is bus-based, so you need one device per slave + 1 for the adapter. x86 already has an I2C bus (actually it's SMBus) that you may be able to use. So you probably want something like -object i2c-linux,file=/dev/i2c-1,id=i2c-backend -device i2c-host,backend=i2c-backend,hostaddr=0x40,address=0x40 -device i2c-host,backend=i2c-backend,hostaddr=0x50,address=0x50 and so on. i2c-linux would be the object issuing ioctls to /dev/i2c-1, multiplexing access to the device for all the i2c-host devices. If the default I2C bus is not good, I suggest that you write QEMU code to emulate an USB-I2C bridge, rather than write a virtio one. It is not a performance-intensive path in all likelihood, and you won't have to write driver code for the guest. Another alternative is to support the kernel's I2C-over-parallel interface. You can then write a character device backend that maps /dev/i2c-1 read/write/ioctl to the parallel port interface that the kernel expects use it with a parallel port device. It would be used like this: -chardev i2c-linux,file=/dev/i2c-1,id=i2c-backend -device parallel,chrdev=i2c-backend Paolo