From patchwork Fri May 10 16:10:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 10939185 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E34CF76 for ; Fri, 10 May 2019 16:13:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D342B28C10 for ; Fri, 10 May 2019 16:13:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C78EC28CB8; Fri, 10 May 2019 16:13:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 55D2928C10 for ; Fri, 10 May 2019 16:13:44 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hP87f-0004Vg-43; Fri, 10 May 2019 16:11:47 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hP87d-0004VU-EV for xen-devel@lists.xenproject.org; Fri, 10 May 2019 16:11:45 +0000 X-Inumbo-ID: 4dc7a623-733e-11e9-8980-bc764e045a96 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 4dc7a623-733e-11e9-8980-bc764e045a96; Fri, 10 May 2019 16:11:44 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.60,453,1549929600"; d="scan'208";a="85330714" From: Roger Pau Monne To: Date: Fri, 10 May 2019 18:10:53 +0200 Message-ID: <20190510161056.48648-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20190510161056.48648-1-roger.pau@citrix.com> References: <20190510161056.48648-1-roger.pau@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/5] pci: use function generation macros for pci_config_{write, read} X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This avoids code duplication between the helpers. No functional change intended. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu --- xen/arch/x86/x86_64/pci.c | 140 ++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 83 deletions(-) diff --git a/xen/arch/x86/x86_64/pci.c b/xen/arch/x86/x86_64/pci.c index 6e3f5cf203..4f77beb119 100644 --- a/xen/arch/x86/x86_64/pci.c +++ b/xen/arch/x86/x86_64/pci.c @@ -11,95 +11,69 @@ #define PCI_CONF_ADDRESS(bus, dev, func, reg) \ (0x80000000 | (bus << 16) | (dev << 11) | (func << 8) | (reg & ~3)) -uint8_t pci_conf_read8( - unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func, - unsigned int reg) -{ - u32 value; - - if ( seg || reg > 255 ) - { - pci_mmcfg_read(seg, bus, PCI_DEVFN(dev, func), reg, 1, &value); - return value; - } - else - { - BUG_ON((bus > 255) || (dev > 31) || (func > 7)); - return pci_conf_read(PCI_CONF_ADDRESS(bus, dev, func, reg), reg & 3, 1); +#define GEN_PCI_CONF_READ(s) \ + uint ## s ## _t pci_conf_read ## s (unsigned int seg, unsigned int bus, \ + unsigned int dev, unsigned int func, \ + unsigned int reg) \ + { \ + uint32_t value; \ + \ + BUILD_BUG_ON(s != 8 && s != 16 && s != 32); \ + if ( seg || reg > 255 ) \ + pci_mmcfg_read(seg, bus, PCI_DEVFN(dev, func), reg, s / 8, &value);\ + else \ + { \ + BUG_ON((bus > 255) || (dev > 31) || (func > 7)); \ + value = pci_conf_read(PCI_CONF_ADDRESS(bus, dev, func, reg), \ + reg & (4 - s / 8), s / 8); \ + } \ + \ + return value; \ } -} -uint16_t pci_conf_read16( - unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func, - unsigned int reg) -{ - u32 value; +/* Grep fodder */ +#define pci_conf_read8 +#define pci_conf_read16 +#define pci_conf_read32 - if ( seg || reg > 255 ) - { - pci_mmcfg_read(seg, bus, PCI_DEVFN(dev, func), reg, 2, &value); - return value; - } - else - { - BUG_ON((bus > 255) || (dev > 31) || (func > 7)); - return pci_conf_read(PCI_CONF_ADDRESS(bus, dev, func, reg), reg & 2, 2); - } -} +#undef pci_conf_read8 +#undef pci_conf_read16 +#undef pci_conf_read32 -uint32_t pci_conf_read32( - unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func, - unsigned int reg) -{ - u32 value; +GEN_PCI_CONF_READ(8) +GEN_PCI_CONF_READ(16) +GEN_PCI_CONF_READ(32) - if ( seg || reg > 255 ) - { - pci_mmcfg_read(seg, bus, PCI_DEVFN(dev, func), reg, 4, &value); - return value; - } - else - { - BUG_ON((bus > 255) || (dev > 31) || (func > 7)); - return pci_conf_read(PCI_CONF_ADDRESS(bus, dev, func, reg), 0, 4); - } -} +#undef GEN_PCI_CONF_READ -void pci_conf_write8( - unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func, - unsigned int reg, uint8_t data) -{ - if ( seg || reg > 255 ) - pci_mmcfg_write(seg, bus, PCI_DEVFN(dev, func), reg, 1, data); - else - { - BUG_ON((bus > 255) || (dev > 31) || (func > 7)); - pci_conf_write(PCI_CONF_ADDRESS(bus, dev, func, reg), reg & 3, 1, data); +#define GEN_PCI_CONF_WRITE(s) \ + void pci_conf_write ## s (unsigned int seg, unsigned int bus, \ + unsigned int dev, unsigned int func, \ + unsigned int reg, uint ## s ## _t data) \ + { \ + BUILD_BUG_ON(s != 8 && s != 16 && s != 32); \ + if ( seg || reg > 255 ) \ + pci_mmcfg_write(seg, bus, PCI_DEVFN(dev, func), reg, s / 8, data); \ + else \ + { \ + BUG_ON((bus > 255) || (dev > 31) || (func > 7)); \ + pci_conf_write(PCI_CONF_ADDRESS(bus, dev, func, reg), \ + reg & (4 - s / 8), s / 8, data); \ + } \ } -} -void pci_conf_write16( - unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func, - unsigned int reg, uint16_t data) -{ - if ( seg || reg > 255 ) - pci_mmcfg_write(seg, bus, PCI_DEVFN(dev, func), reg, 2, data); - else - { - BUG_ON((bus > 255) || (dev > 31) || (func > 7)); - pci_conf_write(PCI_CONF_ADDRESS(bus, dev, func, reg), reg & 2, 2, data); - } -} +/* Grep fodder */ +#define pci_conf_write8 +#define pci_conf_write16 +#define pci_conf_write32 + +#undef pci_conf_write8 +#undef pci_conf_write16 +#undef pci_conf_write32 + +GEN_PCI_CONF_WRITE(8) +GEN_PCI_CONF_WRITE(16) +GEN_PCI_CONF_WRITE(32) + +#undef GEN_PCI_CONF_WRITE -void pci_conf_write32( - unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func, - unsigned int reg, uint32_t data) -{ - if ( seg || reg > 255 ) - pci_mmcfg_write(seg, bus, PCI_DEVFN(dev, func), reg, 4, data); - else - { - BUG_ON((bus > 255) || (dev > 31) || (func > 7)); - pci_conf_write(PCI_CONF_ADDRESS(bus, dev, func, reg), 0, 4, data); - } -}