From patchwork Sun Mar 29 15:04:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 6117321 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6A2F49F32E for ; Sun, 29 Mar 2015 15:07:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8228520295 for ; Sun, 29 Mar 2015 15:07:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8747520272 for ; Sun, 29 Mar 2015 15:06:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752734AbbC2PGp (ORCPT ); Sun, 29 Mar 2015 11:06:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45057 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752804AbbC2PEL (ORCPT ); Sun, 29 Mar 2015 11:04:11 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 62D448E3FA; Sun, 29 Mar 2015 15:04:11 +0000 (UTC) Received: from redhat.com (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id t2TF48qj016939; Sun, 29 Mar 2015 11:04:09 -0400 Date: Sun, 29 Mar 2015 17:04:07 +0200 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Bjorn Helgaas , linux-pci@vger.kernel.org, Fam Zheng , Yinghai Lu , Yijing Wang Subject: [PATCH v5 03/10] pci: drop some duplicate code Message-ID: <1427641227-7574-4-git-send-email-mst@redhat.com> References: <1427641227-7574-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1427641227-7574-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pci_msi_setup_pci_dev and pci_msi_off share a lot of code. This used to be justified since pci_msi_setup_pci_dev wasn't compiled in when CONFIG_PCI_MSI is off. Now that it is, let's reuse code. Since pci_msi_off is used by early quirks, doing this requires calling pci_msi_setup_pci_dev early after device allocation, so move the call to pci_setup_device. Signed-off-by: Michael S. Tsirkin --- drivers/pci/pci.c | 23 ++++------------------- drivers/pci/probe.c | 31 +++++++++++++++---------------- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 81f06e8..fcee8ea 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3106,26 +3106,11 @@ EXPORT_SYMBOL_GPL(pci_check_and_unmask_intx); */ void pci_msi_off(struct pci_dev *dev) { - int pos; - u16 control; + if (dev->msi_cap) + pci_msi_set_enable(dev, 0); - /* - * This looks like it could go in msi.c, but we need it even when - * CONFIG_PCI_MSI=n. For the same reason, we can't use - * dev->msi_cap or dev->msix_cap here. - */ - pos = pci_find_capability(dev, PCI_CAP_ID_MSI); - if (pos) { - pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control); - control &= ~PCI_MSI_FLAGS_ENABLE; - pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control); - } - pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); - if (pos) { - pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control); - control &= ~PCI_MSIX_FLAGS_ENABLE; - pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); - } + if (dev->msix_cap) + pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0); } EXPORT_SYMBOL_GPL(pci_msi_off); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 50dd934..120772c 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1084,6 +1084,18 @@ int pci_cfg_space_size(struct pci_dev *dev) #define LEGACY_IO_RESOURCE (IORESOURCE_IO | IORESOURCE_PCI_FIXED) +static void pci_msi_setup_pci_dev(struct pci_dev *dev) +{ + dev->msi_cap = pci_find_capability(dev, PCI_CAP_ID_MSI); + dev->msix_cap = pci_find_capability(dev, PCI_CAP_ID_MSIX); + + /* Disable the msi hardware to avoid screaming interrupts + * during boot. This is the power on reset default so + * usually this should be a noop. + */ + pci_msi_off(dev); +} + /** * pci_setup_device - fill in class and map information of a device * @dev: the device structure to fill @@ -1139,6 +1151,9 @@ int pci_setup_device(struct pci_dev *dev) /* "Unknown power state" */ dev->current_state = PCI_UNKNOWN; + /* MSI/MSI-X setup has to be done early since it's used by quirks. */ + pci_msi_setup_pci_dev(dev); + /* Early fixups, before probing the BARs */ pci_fixup_device(pci_fixup_early, dev); /* device class may be changed after fixup */ @@ -1483,26 +1498,10 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) return dev; } -static void pci_msi_setup_pci_dev(struct pci_dev *dev) -{ - /* Disable the msi hardware to avoid screaming interrupts - * during boot. This is the power on reset default so - * usually this should be a noop. - */ - dev->msi_cap = pci_find_capability(dev, PCI_CAP_ID_MSI); - if (dev->msi_cap) - pci_msi_set_enable(dev, 0); - - dev->msix_cap = pci_find_capability(dev, PCI_CAP_ID_MSIX); - if (dev->msix_cap) - pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0); -} - static void pci_init_capabilities(struct pci_dev *dev) { /* MSI/MSI-X list */ pci_msi_init_pci_dev(dev); - pci_msi_setup_pci_dev(dev); /* Buffers for saving PCIe and PCI-X capabilities */ pci_allocate_cap_save_buffers(dev);