From patchwork Tue Aug 12 07:26:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyijing X-Patchwork-Id: 35235 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f200.google.com (mail-ig0-f200.google.com [209.85.213.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 41A1F203C5 for ; Tue, 12 Aug 2014 07:06:32 +0000 (UTC) Received: by mail-ig0-f200.google.com with SMTP id uq10sf22723893igb.11 for ; Tue, 12 Aug 2014 00:06:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=wmRuMvTr+nuAr8Z5l9KBv7C9P4OysMI7JEoa0+SGk4A=; b=aBqBxpE1ZifPfDQFtBSz4spoisexgP7Q80/y5Jlyz6kU5aotRBaHElzS+Av+tZ5OeD JA0GmHc3crJbm++XOt2Cd6u9t0CvXreczTzyj+HjpH3gfRRrkS0wTB+RcF0rMREgHiPt fV31FPlWc7FVV2dGYxkzQZt++/FB0iZ2jymVSOUVmjm8Si312wcbU0pscctt12YcxRtz 6d/tcK+An/SJ7B7AlJN2cCeFlQA6Zsfs4/1/0EMbfPS/d3os2tLUMI1IJqpGJ7aCtumg kVq4KSlHv9Jlf6MvJOsApKtP09+TOOw27T/9D/czI1JBfLFWMpFM1+R69jD7Zw3Bgr1b aMMg== X-Gm-Message-State: ALoCoQmOemuHRQWjnRJMom1AeOpqB243mR/RhFY/AdgJ/pw9gnfjKpk+KgQLlQuWuO+9uHib2JAt X-Received: by 10.42.212.207 with SMTP id gt15mr9973icb.31.1407827191704; Tue, 12 Aug 2014 00:06:31 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.102 with SMTP id i93ls8227qgd.40.gmail; Tue, 12 Aug 2014 00:06:31 -0700 (PDT) X-Received: by 10.220.184.70 with SMTP id cj6mr2189254vcb.5.1407827191607; Tue, 12 Aug 2014 00:06:31 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id 7si3197704vcs.68.2014.08.12.00.06.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 Aug 2014 00:06:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id la4so12811097vcb.19 for ; Tue, 12 Aug 2014 00:06:31 -0700 (PDT) X-Received: by 10.52.164.199 with SMTP id ys7mr8711431vdb.42.1407827191511; Tue, 12 Aug 2014 00:06:31 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp224680vcb; Tue, 12 Aug 2014 00:06:30 -0700 (PDT) X-Received: by 10.66.121.168 with SMTP id ll8mr2686027pab.86.1407827190411; Tue, 12 Aug 2014 00:06:30 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bo7si11791097pdb.222.2014.08.12.00.06.29 for ; Tue, 12 Aug 2014 00:06:30 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932086AbaHLHG2 (ORCPT + 26 others); Tue, 12 Aug 2014 03:06:28 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:51333 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753508AbaHLHDS (ORCPT ); Tue, 12 Aug 2014 03:03:18 -0400 Received: from 172.24.2.119 (EHLO szxeml421-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BYA39900; Tue, 12 Aug 2014 15:02:52 +0800 (CST) Received: from localhost.localdomain (10.175.100.166) by szxeml421-hub.china.huawei.com (10.82.67.160) with Microsoft SMTP Server id 14.3.158.1; Tue, 12 Aug 2014 15:02:35 +0800 From: Yijing Wang To: Bjorn Helgaas CC: , Xinwei Hu , Wuyun , , Marc Zyngier , , Russell King , , , "Arnd Bergmann" , Thomas Gleixner , "H. Peter Anvin" , Konrad Rzeszutek Wilk , , Joerg Roedel , , , "Benjamin Herrenschmidt" , , , Sebastian Ott , "Tony Luck" , , "David S. Miller" , , Chris Metcalf , Yijing Wang Subject: [RFC PATCH 08/20] x86/xen/MSI: Use msi_chip instead of arch func to configure MSI/MSI-X Date: Tue, 12 Aug 2014 15:26:01 +0800 Message-ID: <1407828373-24322-9-git-send-email-wangyijing@huawei.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1407828373-24322-1-git-send-email-wangyijing@huawei.com> References: <1407828373-24322-1-git-send-email-wangyijing@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.100.166] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangyijing@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Introduce a new struct msi_chip xen_msi_chip instead of weak arch functions to configure MSI/MSI-X. Signed-off-by: Yijing Wang CC: Konrad Rzeszutek Wilk --- arch/x86/pci/xen.c | 128 +++++++++++++++++++++++++++++---------------------- 1 files changed, 73 insertions(+), 55 deletions(-) diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c index 55c7858..0c4ed47 100644 --- a/arch/x86/pci/xen.c +++ b/arch/x86/pci/xen.c @@ -156,11 +156,12 @@ static int acpi_register_gsi_xen(struct device *dev, u32 gsi, struct xen_pci_frontend_ops *xen_pci_frontend; EXPORT_SYMBOL_GPL(xen_pci_frontend); -static int xen_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) +static int xen_setup_msi_irqs(struct device *dev, int nvec, int type) { int irq, ret, i; struct msi_desc *msidesc; int *v; + struct pci_dev *pdev = to_pci_dev(dev); if (type == PCI_CAP_ID_MSI && nvec > 1) return 1; @@ -170,14 +171,14 @@ static int xen_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) return -ENOMEM; if (type == PCI_CAP_ID_MSIX) - ret = xen_pci_frontend_enable_msix(dev, v, nvec); + ret = xen_pci_frontend_enable_msix(pdev, v, nvec); else - ret = xen_pci_frontend_enable_msi(dev, v); + ret = xen_pci_frontend_enable_msi(pdev, v); if (ret) goto error; i = 0; - list_for_each_entry(msidesc, &dev->msi_list, list) { - irq = xen_bind_pirq_msi_to_irq(dev, msidesc, v[i], + list_for_each_entry(msidesc, &pdev->msi_list, list) { + irq = xen_bind_pirq_msi_to_irq(pdev, msidesc, v[i], (type == PCI_CAP_ID_MSI) ? nvec : 1, (type == PCI_CAP_ID_MSIX) ? "pcifront-msi-x" : @@ -193,7 +194,7 @@ static int xen_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) return 0; error: - dev_err(&dev->dev, "Xen PCI frontend has not registered MSI/MSI-X support!\n"); + dev_err(dev, "Xen PCI frontend has not registered MSI/MSI-X support!\n"); free: kfree(v); return ret; @@ -218,47 +219,48 @@ static void xen_msi_compose_msg(struct pci_dev *pdev, unsigned int pirq, msg->data = XEN_PIRQ_MSI_DATA; } -static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) +static int xen_hvm_setup_msi_irqs(struct device *dev, int nvec, int type) { int irq, pirq; struct msi_desc *msidesc; struct msi_msg msg; + struct pci_dev *pdev = to_pci_dev(dev); if (type == PCI_CAP_ID_MSI && nvec > 1) return 1; - list_for_each_entry(msidesc, &dev->msi_list, list) { + list_for_each_entry(msidesc, &pdev->msi_list, list) { __read_msi_msg(msidesc, &msg); pirq = MSI_ADDR_EXT_DEST_ID(msg.address_hi) | ((msg.address_lo >> MSI_ADDR_DEST_ID_SHIFT) & 0xff); if (msg.data != XEN_PIRQ_MSI_DATA || xen_irq_from_pirq(pirq) < 0) { - pirq = xen_allocate_pirq_msi(dev, msidesc); + pirq = xen_allocate_pirq_msi(pdev, msidesc); if (pirq < 0) { irq = -ENODEV; goto error; } - xen_msi_compose_msg(dev, pirq, &msg); + xen_msi_compose_msg(pdev, pirq, &msg); __write_msi_msg(msidesc, &msg); - dev_dbg(&dev->dev, "xen: msi bound to pirq=%d\n", pirq); + dev_dbg(dev, "xen: msi bound to pirq=%d\n", pirq); } else { - dev_dbg(&dev->dev, + dev_dbg(dev, "xen: msi already bound to pirq=%d\n", pirq); } - irq = xen_bind_pirq_msi_to_irq(dev, msidesc, pirq, + irq = xen_bind_pirq_msi_to_irq(pdev, msidesc, pirq, (type == PCI_CAP_ID_MSI) ? nvec : 1, (type == PCI_CAP_ID_MSIX) ? "msi-x" : "msi", DOMID_SELF); if (irq < 0) goto error; - dev_dbg(&dev->dev, + dev_dbg(dev, "xen: msi --> pirq=%d --> irq=%d\n", pirq, irq); } return 0; error: - dev_err(&dev->dev, + dev_err(dev, "Xen PCI frontend has not registered MSI/MSI-X support!\n"); return irq; } @@ -266,16 +268,17 @@ error: #ifdef CONFIG_XEN_DOM0 static bool __read_mostly pci_seg_supported = true; -static int xen_initdom_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) +static int xen_initdom_setup_msi_irqs(struct device *dev, int nvec, int type) { int ret = 0; struct msi_desc *msidesc; + struct pci_dev *pdev = to_pci_dev(dev); - list_for_each_entry(msidesc, &dev->msi_list, list) { + list_for_each_entry(msidesc, &pdev->msi_list, list) { struct physdev_map_pirq map_irq; domid_t domid; - domid = ret = xen_find_device_domain_owner(dev); + domid = ret = xen_find_device_domain_owner(pdev); /* N.B. Casting int's -ENODEV to uint16_t results in 0xFFED, * hence check ret value for < 0. */ if (ret < 0) @@ -286,9 +289,9 @@ static int xen_initdom_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) map_irq.type = MAP_PIRQ_TYPE_MSI_SEG; map_irq.index = -1; map_irq.pirq = -1; - map_irq.bus = dev->bus->number | - (pci_domain_nr(dev->bus) << 16); - map_irq.devfn = dev->devfn; + map_irq.bus = pdev->bus->number | + (pci_domain_nr(pdev->bus) << 16); + map_irq.devfn = pdev->devfn; if (type == PCI_CAP_ID_MSI && nvec > 1) { map_irq.type = MAP_PIRQ_TYPE_MULTI_MSI; @@ -297,12 +300,12 @@ static int xen_initdom_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) int pos; u32 table_offset, bir; - pos = dev->msix_cap; - pci_read_config_dword(dev, pos + PCI_MSIX_TABLE, + pos = pdev->msix_cap; + pci_read_config_dword(pdev, pos + PCI_MSIX_TABLE, &table_offset); bir = (u8)(table_offset & PCI_MSIX_TABLE_BIR); - map_irq.table_base = pci_resource_start(dev, bir); + map_irq.table_base = pci_resource_start(pdev, bir); map_irq.entry_nr = msidesc->msi_attrib.entry_nr; } @@ -320,23 +323,23 @@ static int xen_initdom_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) ret = 1; goto out; } - if (ret == -EINVAL && !pci_domain_nr(dev->bus)) { + if (ret == -EINVAL && !pci_domain_nr(pdev->bus)) { map_irq.type = MAP_PIRQ_TYPE_MSI; map_irq.index = -1; map_irq.pirq = -1; - map_irq.bus = dev->bus->number; + map_irq.bus = pdev->bus->number; ret = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq); if (ret != -EINVAL) pci_seg_supported = false; } if (ret) { - dev_warn(&dev->dev, "xen map irq failed %d for %d domain\n", + dev_warn(dev, "xen map irq failed %d for %d domain\n", ret, domid); goto out; } - ret = xen_bind_pirq_msi_to_irq(dev, msidesc, map_irq.pirq, + ret = xen_bind_pirq_msi_to_irq(pdev, msidesc, map_irq.pirq, (type == PCI_CAP_ID_MSI) ? nvec : 1, (type == PCI_CAP_ID_MSIX) ? "msi-x" : "msi", domid); @@ -348,16 +351,17 @@ out: return ret; } -static void xen_initdom_restore_msi_irqs(struct pci_dev *dev) +static void xen_initdom_restore_msi_irqs(struct device *dev) { int ret = 0; + struct pci_dev *pdev = to_pci_dev(dev); if (pci_seg_supported) { struct physdev_pci_device restore_ext; - restore_ext.seg = pci_domain_nr(dev->bus); - restore_ext.bus = dev->bus->number; - restore_ext.devfn = dev->devfn; + restore_ext.seg = pci_domain_nr(pdev->bus); + restore_ext.bus = pdev->bus->number; + restore_ext.devfn = pdev->devfn; ret = HYPERVISOR_physdev_op(PHYSDEVOP_restore_msi_ext, &restore_ext); if (ret == -ENOSYS) @@ -367,33 +371,45 @@ static void xen_initdom_restore_msi_irqs(struct pci_dev *dev) if (!pci_seg_supported) { struct physdev_restore_msi restore; - restore.bus = dev->bus->number; - restore.devfn = dev->devfn; + restore.bus = pdev->bus->number; + restore.devfn = pdev->devfn; ret = HYPERVISOR_physdev_op(PHYSDEVOP_restore_msi, &restore); WARN(ret && ret != -ENOSYS, "restore_msi -> %d\n", ret); } } #endif -static void xen_teardown_msi_irqs(struct pci_dev *dev) +static void xen_teardown_msi_irq(unsigned int irq) { - struct msi_desc *msidesc; - - msidesc = list_entry(dev->msi_list.next, struct msi_desc, list); - if (msidesc->msi_attrib.is_msix) - xen_pci_frontend_disable_msix(dev); - else - xen_pci_frontend_disable_msi(dev); - - /* Free the IRQ's and the msidesc using the generic code. */ - default_teardown_msi_irqs(dev); + xen_destroy_irq(irq); } -static void xen_teardown_msi_irq(unsigned int irq) +static void xen_teardown_msi_irqs(struct device *dev) { - xen_destroy_irq(irq); + struct msi_desc *entry; + struct pci_dev *pdev = to_pci_dev(dev); + + entry = list_entry(pdev->msi_list.next, struct msi_desc, list); + if (entry->msi_attrib.is_msix) + xen_pci_frontend_disable_msix(pdev); + else + xen_pci_frontend_disable_msi(pdev); + + list_for_each_entry(entry, &pdev->msi_list, list) { + int i, nvec; + if (entry->irq == 0) + continue; + if (entry->nvec_used) + nvec = entry->nvec_used; + else + nvec = 1 << entry->msi_attrib.multiple; + for (i = 0; i < nvec; i++) + xen_teardown_msi_irq(entry->irq + i); + } } +struct msi_chip xen_msi_chip; + #endif int __init pci_xen_init(void) @@ -414,9 +430,9 @@ int __init pci_xen_init(void) #endif #ifdef CONFIG_PCI_MSI - x86_msi.setup_msi_irqs = xen_setup_msi_irqs; - x86_msi.teardown_msi_irq = xen_teardown_msi_irq; - x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs; + xen_msi_chip.setup_irqs = xen_setup_msi_irqs; + xen_msi_chip.teardown_irqs = xen_teardown_msi_irqs; + x86_msi_chip = &xen_msi_chip; #endif return 0; } @@ -435,8 +451,9 @@ int __init pci_xen_hvm_init(void) #endif #ifdef CONFIG_PCI_MSI - x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs; - x86_msi.teardown_msi_irq = xen_teardown_msi_irq; + xen_msi_chip.setup_irqs = xen_hvm_setup_msi_irqs; + xen_msi_chip.teardown_irq = xen_teardown_msi_irq; + x86_msi_chip = &xen_msi_chip; #endif return 0; } @@ -493,9 +510,10 @@ int __init pci_xen_initial_domain(void) int irq; #ifdef CONFIG_PCI_MSI - x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs; - x86_msi.teardown_msi_irq = xen_teardown_msi_irq; - x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs; + xen_msi_chip.setup_irqs = xen_initdom_setup_msi_irqs; + xen_msi_chip.teardown_irq = xen_teardown_msi_irq; + xen_msi_chip.restore_irqs = xen_initdom_restore_msi_irqs; + x86_msi_chip = &xen_msi_chip; #endif xen_setup_acpi_sci(); __acpi_register_gsi = acpi_register_gsi_xen;