From nobody Wed May 1 21:50:59 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1557504787; cv=none; d=zoho.com; s=zohoarc; b=fpCHZGBWNJHUpBMyUPAb2BDpVXhSWilq82i0zvjFN21hO3+nuYd5aV0RDLGudH0+4G0+DRHmNyltDapuB5bQOPoDrcZXHdiAcFYbXciBYO9Xsw+ghdv/CkkdAFxeFODl2zbnS2+CyLuzjjDwntfPn8KdPoYxkwr2d51Kb6YxwP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557504787; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=kgYFkjFJ/c6OH/fBTyOg9yMd6JDaSCmDYVUs50tI5YA=; b=Zdhz/6PXV1CJxD6+P198NGgMIPRHOjZSnv1C+ReWuYKoY7tzVhXkKOxWI7Q60YnrPkkFdA6rBdHfnQto+SRn2CrY3zhRygFRIqADv0KvbYFS2h+EN1HYoIKioPpX9nVnBtICYJbtywTewvGdMcxrE/M2tm1XfINMDE+2BDTg4fA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1557504787339326.1468636694093; Fri, 10 May 2019 09:13:07 -0700 (PDT) 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 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-Inumbo-ID: 4dc7a623-733e-11e9-8980-bc764e045a96 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This avoids code duplication between the helpers. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 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)) =20 -uint8_t pci_conf_read8( - unsigned int seg, unsigned int bus, unsigned int dev, unsigned int fun= c, - 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 fun= c, \ + unsigned int reg) = \ + { = \ + uint32_t value; = \ + = \ + BUILD_BUG_ON(s !=3D 8 && s !=3D 16 && s !=3D 32); = \ + if ( seg || reg > 255 ) = \ + pci_mmcfg_read(seg, bus, PCI_DEVFN(dev, func), reg, s / 8, &va= lue);\ + else = \ + { = \ + BUG_ON((bus > 255) || (dev > 31) || (func > 7)); = \ + value =3D pci_conf_read(PCI_CONF_ADDRESS(bus, dev, func, reg),= \ + reg & (4 - s / 8), s / 8); = \ + } = \ + = \ + return value; = \ } -} =20 -uint16_t pci_conf_read16( - unsigned int seg, unsigned int bus, unsigned int dev, unsigned int fun= c, - unsigned int reg) -{ - u32 value; +/* Grep fodder */ +#define pci_conf_read8 +#define pci_conf_read16 +#define pci_conf_read32 =20 - 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 =20 -uint32_t pci_conf_read32( - unsigned int seg, unsigned int bus, unsigned int dev, unsigned int fun= c, - unsigned int reg) -{ - u32 value; +GEN_PCI_CONF_READ(8) +GEN_PCI_CONF_READ(16) +GEN_PCI_CONF_READ(32) =20 - 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 =20 -void pci_conf_write8( - unsigned int seg, unsigned int bus, unsigned int dev, unsigned int fun= c, - 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 !=3D 8 && s !=3D 16 && s !=3D 32); = \ + if ( seg || reg > 255 ) = \ + pci_mmcfg_write(seg, bus, PCI_DEVFN(dev, func), reg, s / 8, da= ta); \ + 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); = \ + } = \ } -} =20 -void pci_conf_write16( - unsigned int seg, unsigned int bus, unsigned int dev, unsigned int fun= c, - 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 =20 -void pci_conf_write32( - unsigned int seg, unsigned int bus, unsigned int dev, unsigned int fun= c, - 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); - } -} --=20 2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel