From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=34026 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PARwq-0001ML-6o for qemu-devel@nongnu.org; Mon, 25 Oct 2010 14:39:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PARwo-00030F-Of for qemu-devel@nongnu.org; Mon, 25 Oct 2010 14:39:08 -0400 Received: from mail-qw0-f45.google.com ([209.85.216.45]:41751) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PARwo-0002zw-LZ for qemu-devel@nongnu.org; Mon, 25 Oct 2010 14:39:06 -0400 Received: by qwf7 with SMTP id 7so1801949qwf.4 for ; Mon, 25 Oct 2010 11:39:05 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <4CC55554.4060103@redhat.com> References: <1287934469-16624-1-git-send-email-avi@redhat.com> <1287934469-16624-2-git-send-email-avi@redhat.com> <4CC55554.4060103@redhat.com> From: Blue Swirl Date: Mon, 25 Oct 2010 18:38:42 +0000 Message-ID: Subject: Re: [Qemu-devel] [PATCH 1/2] Type-safe ioport callbacks Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org On Mon, Oct 25, 2010 at 10:00 AM, Avi Kivity wrote: > =C2=A0On 10/24/2010 08:14 PM, Blue Swirl wrote: >> >> On Sun, Oct 24, 2010 at 3:34 PM, Avi Kivity =C2=A0wrote: >> > =C2=A0The current ioport callbacks are not type-safe, in that they acc= ept an >> > "opaque" >> > =C2=A0pointer as an argument whose type must match the argument to the >> > registration >> > =C2=A0function; this is not checked by the compiler. >> > >> > =C2=A0This patch adds an alternative that is type-safe. =C2=A0Instead = of an opaque >> > =C2=A0argument, both registation and the callback use a new IOPort typ= e. =C2=A0The >> > =C2=A0callback then uses container_of() to access its main structures. >> > >> > =C2=A0Currently the old and new methods exist side by side; once the o= ld way >> > is gone, >> > =C2=A0we can also save a bunch of memory since the new method requires= one >> > pointer >> > =C2=A0per ioport instead of 6. >> > >> > =C2=A0Signed-off-by: Avi Kivity >> >> If we are going to change the interface, let's do it so that it's >> useful for other uses too: >> http://article.gmane.org/gmane.comp.emulators.qemu/76984 > > I don't really see why we need registration; cpu_register_io() takes > function pointers, a size, and an opaque, and gives an integer handle in > return. =C2=A0With the IOPort object approach, you set up the IOPort with > function pointers, size is implied, and the opaque is derived using > container_of(); the handle is simply the address of the object. With the handle, we can separate setting up the structures at device level, and mapping the object using only the handle at bus or other higher level. Can this be done with the object approach? The purpose of that patch series was to perform the separation for PCI BARs. I wasn't so happy with the series, so I never pushed.