From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=33979 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P7kJT-0004Jk-Qz for qemu-devel@nongnu.org; Mon, 18 Oct 2010 03:39:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P7kJS-0002AT-FR for qemu-devel@nongnu.org; Mon, 18 Oct 2010 03:39:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56442) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P7kJS-0002AM-8i for qemu-devel@nongnu.org; Mon, 18 Oct 2010 03:39:18 -0400 Date: Mon, 18 Oct 2010 09:32:18 +0200 From: "Michael S. Tsirkin" Message-ID: <20101018073218.GA20298@redhat.com> References: <7d5d92f508899391d060809e9a419c7556905379.1287371107.git.yamahata@valinux.co.jp> <20101018053853.GC18366@redhat.com> <20101018071740.GD31699@valinux.co.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20101018071740.GD31699@valinux.co.jp> Subject: [Qemu-devel] Re: [PATCH v4 04/15] pci: record which is written into pci configuration space List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Isaku Yamahata Cc: skandasa@cisco.com, adnan@khaleel.us, etmartin@cisco.com, qemu-devel@nongnu.org, wexu2@cisco.com On Mon, Oct 18, 2010 at 04:17:40PM +0900, Isaku Yamahata wrote: > On Mon, Oct 18, 2010 at 07:38:53AM +0200, Michael S. Tsirkin wrote: > > On Mon, Oct 18, 2010 at 12:17:45PM +0900, Isaku Yamahata wrote: > > > record which is written into pci configuration space. > > > introduce helper function to zero PCIDevice::written. > > > They will be used later. > > > > > > Signed-off-by: Isaku Yamahata > > > > This really exposes an internal variable. > > I really dislike this, and I don't think it's needed > > at all: just make the bit writeable. > > Commented on appropriate patches. > > I see. So You really want those bit writable. > Then how about introducing pci_{byte, word, long}_test_and_clear_mask() > helper functions? okay, but then let's get rid of simple _clear/_set then: the side effect or returning old value is harmless. Also pls add a comment noting these are not atomic. > > > > > > > --- > > > hw/pci.c | 10 ++++++++++ > > > hw/pci.h | 5 +++++ > > > 2 files changed, 15 insertions(+), 0 deletions(-) > > > > > > diff --git a/hw/pci.c b/hw/pci.c > > > index 5954476..eca9324 100644 > > > --- a/hw/pci.c > > > +++ b/hw/pci.c > > > @@ -627,6 +627,7 @@ static void pci_config_alloc(PCIDevice *pci_dev) > > > pci_dev->cmask = qemu_mallocz(config_size); > > > pci_dev->wmask = qemu_mallocz(config_size); > > > pci_dev->w1cmask = qemu_mallocz(config_size); > > > + pci_dev->written = qemu_mallocz(config_size); > > > pci_dev->used = qemu_mallocz(config_size); > > > } > > > > > > @@ -636,6 +637,7 @@ static void pci_config_free(PCIDevice *pci_dev) > > > qemu_free(pci_dev->cmask); > > > qemu_free(pci_dev->wmask); > > > qemu_free(pci_dev->w1cmask); > > > + qemu_free(pci_dev->written); > > > qemu_free(pci_dev->used); > > > } > > > > > > @@ -1002,6 +1004,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l) > > > assert(!(wmask & w1cmask)); > > > d->config[addr + i] = (d->config[addr + i] & ~wmask) | (val & wmask); > > > d->config[addr + i] &= ~(val & w1cmask); /* W1C: Write 1 to Clear */ > > > + d->written[addr + i] = val; /* record what is written for driver > > > + specific code */ > > > } > > > if (ranges_overlap(addr, l, PCI_BASE_ADDRESS_0, 24) || > > > ranges_overlap(addr, l, PCI_ROM_ADDRESS, 4) || > > > @@ -1013,6 +1017,12 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l) > > > pci_update_irq_disabled(d, was_irq_disabled); > > > } > > > > > > +void pci_clear_written_write_config(PCIDevice *d, > > > + uint32_t addr, uint32_t val, int l) > > > +{ > > > + memset(d->written + addr, 0, l); > > > +} > > > + > > > /***********************************************************/ > > > /* generic PCI irq support */ > > > > > > diff --git a/hw/pci.h b/hw/pci.h > > > index eafa9f3..7097817 100644 > > > --- a/hw/pci.h > > > +++ b/hw/pci.h > > > @@ -132,6 +132,9 @@ struct PCIDevice { > > > /* Used to implement RW1C(Write 1 to Clear) bytes */ > > > uint8_t *w1cmask; > > > > > > + /* Used to record what value is written */ > > > + uint8_t *written; > > > + > > > /* Used to allocate config space for capabilities. */ > > > uint8_t *used; > > > > > > @@ -200,6 +203,8 @@ uint32_t pci_default_read_config(PCIDevice *d, > > > uint32_t address, int len); > > > void pci_default_write_config(PCIDevice *d, > > > uint32_t address, uint32_t val, int len); > > > +void pci_clear_written_write_config(PCIDevice *d, > > > + uint32_t addr, uint32_t val, int l); > > > void pci_device_save(PCIDevice *s, QEMUFile *f); > > > int pci_device_load(PCIDevice *s, QEMUFile *f); > > > > > > -- > > > 1.7.1.1 > > > > -- > yamahata