From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=34794 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDGvp-0003tb-5P for qemu-devel@nongnu.org; Tue, 02 Nov 2010 09:29:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDFZ2-0007cT-1R for qemu-devel@nongnu.org; Tue, 02 Nov 2010 08:02:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9574) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PDFZ1-0007ar-Qq for qemu-devel@nongnu.org; Tue, 02 Nov 2010 08:02:08 -0400 Date: Tue, 2 Nov 2010 14:02:02 +0200 From: "Michael S. Tsirkin" Message-ID: <20101102120202.GA29492@redhat.com> References: <20101102053544.10424.42769.stgit@s20.home> <20101102053727.10424.32902.stgit@s20.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20101102053727.10424.32902.stgit@s20.home> Subject: [Qemu-devel] Re: [PATCH 1/3] msi: Allow pre-existing MSI capabilities List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Williamson Cc: yamahata@valinux.co.jp, qemu-devel@nongnu.org On Mon, Nov 01, 2010 at 11:37:32PM -0600, Alex Williamson wrote: > For use with device assignment, allow calling msi_init() on devices > with MSI capability already configured. > > Signed-off-by: Alex Williamson Looks like the same find/add trick is repeated all over: you put it in msix and now in msi. How about we teach pci_add_capability about this functionality? Then if offset is != 0 and capability is found, we can assert. > --- > > hw/msi.c | 12 +++++++++--- > 1 files changed, 9 insertions(+), 3 deletions(-) > > diff --git a/hw/msi.c b/hw/msi.c > index f03f519..0ad4e38 100644 > --- a/hw/msi.c > +++ b/hw/msi.c > @@ -135,10 +135,16 @@ int msi_init(struct PCIDevice *dev, uint8_t offset, > flags |= PCI_MSI_FLAGS_MASKBIT; > } > > + config_offset = pci_find_capability(dev, PCI_CAP_ID_MSI); > + > cap_size = msi_cap_sizeof(flags); > - config_offset = pci_add_capability(dev, PCI_CAP_ID_MSI, offset, cap_size); > - if (config_offset < 0) { > - return config_offset; > + > + if (!config_offset) { > + config_offset = pci_add_capability(dev, PCI_CAP_ID_MSI, > + offset, cap_size); > + if (config_offset < 0) { > + return config_offset; > + } > } > > dev->msi_cap = config_offset;