From patchwork Fri Oct 9 06:28:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 35574 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EF7F3B7B92 for ; Fri, 9 Oct 2009 18:10:47 +1100 (EST) Received: from localhost ([127.0.0.1]:53994 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mw9ci-0008Kf-SC for incoming@patchwork.ozlabs.org; Fri, 09 Oct 2009 03:10:44 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mw90N-0004Di-JA for qemu-devel@nongnu.org; Fri, 09 Oct 2009 02:31:07 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mw90D-00042e-7d for qemu-devel@nongnu.org; Fri, 09 Oct 2009 02:31:01 -0400 Received: from [199.232.76.173] (port=55782 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mw90C-00042E-Uq for qemu-devel@nongnu.org; Fri, 09 Oct 2009 02:30:57 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:36132) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mw907-0001Q3-Az for qemu-devel@nongnu.org; Fri, 09 Oct 2009 02:30:52 -0400 Received: from nm.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with ESMTP id 552F049E2D; Fri, 9 Oct 2009 15:30:41 +0900 (JST) Received: from yamahata by nm.local.valinux.co.jp with local (Exim 4.69) (envelope-from ) id 1Mw8yN-00047D-6Y; Fri, 09 Oct 2009 15:29:03 +0900 From: Isaku Yamahata To: qemu-devel@nongnu.org, mst@redhat.com Date: Fri, 9 Oct 2009 15:28:58 +0900 Message-Id: <1255069742-15724-26-git-send-email-yamahata@valinux.co.jp> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1255069742-15724-1-git-send-email-yamahata@valinux.co.jp> References: <1255069742-15724-1-git-send-email-yamahata@valinux.co.jp> X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: yamahata@valinux.co.jp Subject: [Qemu-devel] [PATCH V5 25/29] pci: add helper functions for pci config write function. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org add helper functions for pci config write function to check if its configuration space is changed. To detect the change in configuration space, memcpy the original value and memcmp with updated value. The original value is allocated in PCIDevice because its length might be 4K for pci express which is a bit too large for stack. Those functions will be used later and generic enough for specific pci device to use. Signed-off-by: Isaku Yamahata --- hw/pci.c | 2 ++ hw/pci.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 8e396b6..ece429f 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -446,6 +446,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->used = qemu_mallocz(config_size); + pci_dev->orig = qemu_mallocz(config_size); } static void pci_config_free(PCIDevice *pci_dev) @@ -454,6 +455,7 @@ static void pci_config_free(PCIDevice *pci_dev) qemu_free(pci_dev->cmask); qemu_free(pci_dev->wmask); qemu_free(pci_dev->used); + qemu_free(pci_dev->orig); } /* -1 for devfn means auto assign */ diff --git a/hw/pci.h b/hw/pci.h index bfa29c8..2896b0e 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -192,6 +192,9 @@ struct PCIDevice { /* Used to allocate config space for capabilities. */ uint8_t *used; + /* Used to implement configuration space change */ + uint8_t *orig; + /* the following fields are read only */ PCIBus *bus; uint32_t devfn; @@ -388,6 +391,53 @@ static inline uint32_t pci_config_size(PCIDevice *d) return pci_is_express(d) ? PCIE_CONFIG_SPACE_SIZE : PCI_CONFIG_SPACE_SIZE; } +struct pci_config_update { + PCIDevice *d; + uint32_t addr; + uint32_t val; + int len; +}; + +static inline void pci_write_config_init(struct pci_config_update *update, + PCIDevice *d, + uint32_t addr, uint32_t val, int len) +{ + update->d = d; + update->addr = addr; + update->val = val; + update->len = len; + memcpy(d->orig, d->config, pci_config_size(d)); +} + +static inline void pci_write_config_update(struct pci_config_update *update) +{ + PCIDevice *d = update->d; + uint32_t addr = update->addr; + uint32_t val = update->val; + uint32_t config_size = pci_config_size(d); + int i; + + for(i = 0; i < update->len && addr < config_size; val >>= 8, ++i, ++addr) { + uint8_t wmask = d->wmask[addr]; + d->config[addr] = (d->config[addr] & ~wmask) | (val & wmask); + } +} + +/* check if [base, end) in configuration space is changed */ +static inline int pci_config_changed(const struct pci_config_update *update, + uint32_t base, uint32_t end) +{ + return memcmp(update->d->orig + base, update->d->config + base, + end - base); +} + +/* for convinience not to type symbol constant twice */ +static inline int pci_config_changed_with_size( + const struct pci_config_update *update, uint32_t base, uint32_t size) +{ + return pci_config_changed(update, base, base + size); +} + /* lsi53c895a.c */ #define LSI_MAX_DEVS 7