From patchwork Sun Mar 18 17:06:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 147405 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EB177B6FB4 for ; Mon, 19 Mar 2012 04:06:33 +1100 (EST) Received: from localhost ([::1]:57184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9JYt-0001bm-L7 for incoming@patchwork.ozlabs.org; Sun, 18 Mar 2012 13:06:31 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60195) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9JYe-0001RY-TJ for qemu-devel@nongnu.org; Sun, 18 Mar 2012 13:06:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9JYd-0005si-1v for qemu-devel@nongnu.org; Sun, 18 Mar 2012 13:06:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10362) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9JYc-0005sc-Qw for qemu-devel@nongnu.org; Sun, 18 Mar 2012 13:06:14 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2IH6CwY000472 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 18 Mar 2012 13:06:12 -0400 Received: from redhat.com (reserved-200-253.tlv.redhat.com [10.35.200.253] (may be forged)) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id q2IH69rw007037; Sun, 18 Mar 2012 13:06:10 -0400 Date: Sun, 18 Mar 2012 19:06:29 +0200 From: "Michael S. Tsirkin" To: Alex Williamson , gleb@redhat.com, Anthony Liguori , qemu-devel@nongnu.org Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mutt-Fcc: =sent User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] pci: track function accesses X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Set a flag when function is first accessed after system reset. Signed-off-by: Michael S. Tsirkin --- hw/pci.c | 26 ++++++++++++++++++++++++++ hw/pci.h | 3 +++ hw/pci_host.c | 2 ++ 3 files changed, 31 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index b706e69..2aaa45e 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -407,6 +407,17 @@ static VMStateInfo vmstate_info_pci_irq_state = { .put = put_pci_irq_state, }; +static const VMStateDescription pci_vmstate_accessed_since_reset ={ + .name = "pci/accessed_since_reset", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField []) { + VMSTATE_BOOL(accessed_since_reset, PCIDevice), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_pci_device = { .name = "PCIDevice", .version_id = 2, @@ -421,6 +432,12 @@ const VMStateDescription vmstate_pci_device = { vmstate_info_pci_irq_state, PCI_NUM_PINS * sizeof(int32_t)), VMSTATE_END_OF_LIST() + }, + .subsections = (VMStateSubsection[]) { + { + .vmsd = &pci_vmstate_accessed_since_reset, + }, + VMSTATE_END_OF_LIST() } }; @@ -738,6 +755,12 @@ static void pci_config_free(PCIDevice *pci_dev) g_free(pci_dev->used); } +static void pci_system_reset_fn(void *opaque) +{ + PCIDevice *dev = opaque; + dev->accessed_since_reset = false; +} + /* -1 for devfn means auto assign */ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, const char *name, int devfn) @@ -805,11 +828,14 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, bus->devices[devfn] = pci_dev; pci_dev->irq = qemu_allocate_irqs(pci_set_irq, pci_dev, PCI_NUM_PINS); pci_dev->version_id = 2; /* Current pci device vmstate version */ + pci_dev->accessed_since_reset = false; + qemu_register_reset(pci_system_reset_fn, pci_dev); return pci_dev; } static void do_pci_unregister_device(PCIDevice *pci_dev) { + qemu_unregister_reset(pci_system_reset_fn, pci_dev); qemu_free_irqs(pci_dev->irq); pci_dev->bus->devices[pci_dev->devfn] = NULL; pci_config_free(pci_dev); diff --git a/hw/pci.h b/hw/pci.h index 8d0aa49..3fdd1dc 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -243,6 +243,9 @@ struct PCIDevice { bool has_rom; MemoryRegion rom; uint32_t rom_bar; + + /* Cleared on first access after system reset */ + bool accessed_since_reset; }; void pci_register_bar(PCIDevice *pci_dev, int region_num, diff --git a/hw/pci_host.c b/hw/pci_host.c index 44c6c20..3019d72 100644 --- a/hw/pci_host.c +++ b/hw/pci_host.c @@ -51,6 +51,7 @@ void pci_host_config_write_common(PCIDevice *pci_dev, uint32_t addr, uint32_t limit, uint32_t val, uint32_t len) { assert(len <= 4); + pci_dev->accessed_since_reset = true; pci_dev->config_write(pci_dev, addr, val, MIN(len, limit - addr)); } @@ -58,6 +59,7 @@ uint32_t pci_host_config_read_common(PCIDevice *pci_dev, uint32_t addr, uint32_t limit, uint32_t len) { assert(len <= 4); + pci_dev->accessed_since_reset = true; return pci_dev->config_read(pci_dev, addr, MIN(len, limit - addr)); }