From patchwork Tue Jan 12 08:52:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 42693 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 C0F11B7C5A for ; Tue, 12 Jan 2010 20:07:53 +1100 (EST) Received: from localhost ([127.0.0.1]:34318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NUchV-0007CD-50 for incoming@patchwork.ozlabs.org; Tue, 12 Jan 2010 04:06:09 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NUcUh-0003IZ-LA for qemu-devel@nongnu.org; Tue, 12 Jan 2010 03:52:55 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NUcUb-0003Ee-VD for qemu-devel@nongnu.org; Tue, 12 Jan 2010 03:52:54 -0500 Received: from [199.232.76.173] (port=52553 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NUcUb-0003EW-R0 for qemu-devel@nongnu.org; Tue, 12 Jan 2010 03:52:49 -0500 Received: from mail.valinux.co.jp ([210.128.90.3]:41488) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NUcUa-00018T-Q8 for qemu-devel@nongnu.org; Tue, 12 Jan 2010 03:52:49 -0500 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id D2478182B3; Tue, 12 Jan 2010 17:52:45 +0900 (JST) Received: (nullmailer pid 10436 invoked by uid 1000); Tue, 12 Jan 2010 08:52:59 -0000 From: Isaku Yamahata To: qemu-devel@nongnu.org Date: Tue, 12 Jan 2010 17:52:56 +0900 Message-Id: <1263286378-10398-5-git-send-email-yamahata@valinux.co.jp> X-Mailer: git-send-email 1.6.5.4 In-Reply-To: <1263286378-10398-1-git-send-email-yamahata@valinux.co.jp> References: <1263286378-10398-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, agraf@suse.de, mst@redhat.com Subject: [Qemu-devel] [PATCH 4/6] pci_host: remove code duplication in pci_host_template.h 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 Remove code duplication in pci_host_template.h by using cpp trick. Based on Alexander Graf patch. Cc: Alexander Graf Signed-off-by: Isaku Yamahata --- hw/pci_host.c | 4 +- hw/pci_host_template.h | 82 +++++++++---------------------------------- hw/pci_host_template_all.h | 23 ++++++++++++ 3 files changed, 42 insertions(+), 67 deletions(-) create mode 100644 hw/pci_host_template_all.h diff --git a/hw/pci_host.c b/hw/pci_host.c index 6289ead..307f7d4 100644 --- a/hw/pci_host.c +++ b/hw/pci_host.c @@ -190,7 +190,7 @@ void pci_host_conf_register_ioport(pio_addr_t ioport, PCIHostState *s) #define PCI_ADDR_T target_phys_addr_t #define PCI_HOST_SUFFIX _mmio -#include "pci_host_template.h" +#include "pci_host_template_all.h" static CPUWriteMemoryFunc * const pci_host_data_write_mmio[] = { pci_host_data_writeb_mmio, @@ -217,7 +217,7 @@ int pci_host_data_register_mmio(PCIHostState *s) #define PCI_ADDR_T uint32_t #define PCI_HOST_SUFFIX _ioport -#include "pci_host_template.h" +#include "pci_host_template_all.h" void pci_host_data_register_ioport(pio_addr_t ioport, PCIHostState *s) { diff --git a/hw/pci_host_template.h b/hw/pci_host_template.h index 11e6c88..2c508bf 100644 --- a/hw/pci_host_template.h +++ b/hw/pci_host_template.h @@ -25,85 +25,37 @@ /* Worker routines for a PCI host controller that uses an {address,data} register pair to access PCI configuration space. */ -static void glue(pci_host_data_writeb, PCI_HOST_SUFFIX)( +static void glue(glue(pci_host_data_write, PCI_HOST_BWL), PCI_HOST_SUFFIX)( void* opaque, PCI_ADDR_T addr, uint32_t val) { PCIHostState *s = opaque; - PCI_DPRINTF("writeb addr " TARGET_FMT_plx " val %x\n", - (target_phys_addr_t)addr, val); - if (s->config_reg & (1u << 31)) - pci_data_write(s->bus, s->config_reg | (addr & 3), val, 1); -} - -static void glue(pci_host_data_writew, PCI_HOST_SUFFIX)( - void* opaque, PCI_ADDR_T addr, uint32_t val) -{ - PCIHostState *s = opaque; -#ifdef TARGET_WORDS_BIGENDIAN - val = bswap16(val); -#endif - PCI_DPRINTF("writew addr " TARGET_FMT_plx " val %x\n", - (target_phys_addr_t)addr, val); - if (s->config_reg & (1u << 31)) - pci_data_write(s->bus, s->config_reg | (addr & 3), val, 2); -} - -static void glue(pci_host_data_writel, PCI_HOST_SUFFIX)( - void* opaque, PCI_ADDR_T addr, uint32_t val) -{ - PCIHostState *s = opaque; -#ifdef TARGET_WORDS_BIGENDIAN - val = bswap32(val); +#if defined(TARGET_WORDS_BIGENDIAN) && (PCI_HOST_BITS > 8) + val = glue(bswap, PCI_HOST_BITS)(val); #endif - PCI_DPRINTF("writel addr " TARGET_FMT_plx " val %x\n", - (target_phys_addr_t)addr, val); + PCI_DPRINTF("%s: addr " TARGET_FMT_plx " val %x\n", + __func__, (target_phys_addr_t)addr, val); if (s->config_reg & (1u << 31)) - pci_data_write(s->bus, s->config_reg, val, 4); + pci_data_write(s->bus, s->config_reg | (addr & 3), val, + sizeof(glue(glue(uint, PCI_HOST_BITS), _t))); } -static uint32_t glue(pci_host_data_readb, PCI_HOST_SUFFIX)( +static uint32_t glue(glue(pci_host_data_read, PCI_HOST_BWL), PCI_HOST_SUFFIX)( void* opaque, PCI_ADDR_T addr) { PCIHostState *s = opaque; uint32_t val; - if (!(s->config_reg & (1 << 31))) - return 0xff; - val = pci_data_read(s->bus, s->config_reg | (addr & 3), 1); - PCI_DPRINTF("readb addr " TARGET_FMT_plx " val %x\n", - (target_phys_addr_t)addr, val); - return val; -} + if (!(s->config_reg & (1 << 31))) { + return ( 1ULL << PCI_HOST_BITS ) - 1; + } -static uint32_t glue(pci_host_data_readw, PCI_HOST_SUFFIX)( - void* opaque, PCI_ADDR_T addr) -{ - PCIHostState *s = opaque; - uint32_t val; - if (!(s->config_reg & (1 << 31))) - return 0xffff; - val = pci_data_read(s->bus, s->config_reg | (addr & 3), 2); - PCI_DPRINTF("readw addr " TARGET_FMT_plx " val %x\n", - (target_phys_addr_t)addr, val); -#ifdef TARGET_WORDS_BIGENDIAN - val = bswap16(val); -#endif - return val; -} - -static uint32_t glue(pci_host_data_readl, PCI_HOST_SUFFIX)( - void* opaque, PCI_ADDR_T addr) -{ - PCIHostState *s = opaque; - uint32_t val; - if (!(s->config_reg & (1 << 31))) - return 0xffffffff; - val = pci_data_read(s->bus, s->config_reg | (addr & 3), 4); - PCI_DPRINTF("readl addr " TARGET_FMT_plx " val %x\n", - (target_phys_addr_t)addr, val); -#ifdef TARGET_WORDS_BIGENDIAN - val = bswap32(val); + val = pci_data_read(s->bus, s->config_reg | (addr & 3), + sizeof(glue(glue(uint, PCI_HOST_BITS), _t))); + PCI_DPRINTF("%s addr " TARGET_FMT_plx " val %x\n", + __func__, (target_phys_addr_t)addr, val); +#if defined(TARGET_WORDS_BIGENDIAN) && (PCI_HOST_BITS > 8) + val = glue(bswap, PCI_HOST_BITS)(val); #endif return val; } diff --git a/hw/pci_host_template_all.h b/hw/pci_host_template_all.h new file mode 100644 index 0000000..74b3e84 --- /dev/null +++ b/hw/pci_host_template_all.h @@ -0,0 +1,23 @@ +#define PCI_HOST_BWL b +#define PCI_HOST_BITS 8 + +#include "pci_host_template.h" + +#undef PCI_HOST_BWL +#undef PCI_HOST_BITS + +#define PCI_HOST_BWL w +#define PCI_HOST_BITS 16 + +#include "pci_host_template.h" + +#undef PCI_HOST_BWL +#undef PCI_HOST_BITS + +#define PCI_HOST_BWL l +#define PCI_HOST_BITS 32 + +#include "pci_host_template.h" + +#undef PCI_HOST_BWL +#undef PCI_HOST_BITS