From patchwork Sat Aug 5 06:37:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 9882895 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2C5DF602B6 for ; Sat, 5 Aug 2017 06:39:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 106BD288C9 for ; Sat, 5 Aug 2017 06:39:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3AF7288C7; Sat, 5 Aug 2017 06:39:41 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A735288C7 for ; Sat, 5 Aug 2017 06:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751398AbdHEGi3 (ORCPT ); Sat, 5 Aug 2017 02:38:29 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36202 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751371AbdHEGi2 (ORCPT ); Sat, 5 Aug 2017 02:38:28 -0400 Received: by mail-pf0-f196.google.com with SMTP id t83so3773187pfj.3; Fri, 04 Aug 2017 23:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=VEOzeO/8fsyXCQZoDBLto7PS+U5kV8ImIl8iTrh3rgA=; b=gZ+04TfllEuonVleyZrdbDKXL/zL534xc/ioJuTQzWCNCWt9NbD+JreVoYSjWFyIn5 ZtDVQtPlvhuvj5QWbCySn1LRaQ3CWUMJoqJ06d62gz2Ykt/be48/n5IKBGD7V3bfyXg3 gslVKMpiPKJU3y1LNk0NYLEzaKNpPUSM919rc1YbUZai7YbCF87HJ/kJXaR6nUIGS0nF MU0+Wzi3VdoD8QzfShfY0Q9ZoQW61KqmkAFkRTzFD7p/xCYnreV8W0O94yo79mzOzD3e lm4SKrsQM3WjC+1Bf/f7COLZz6Xy+TyFLL8+SaOohFPQiidFNJo/4lW/OeIDzPFbJmb2 30rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=VEOzeO/8fsyXCQZoDBLto7PS+U5kV8ImIl8iTrh3rgA=; b=TGUiuoJ9XmhZhODaCUXKfgVb6v7vmr7+Y3XT3ElvNQ2Hc+pFywF234nrBb58x/+rmb ru9oBBfnHFwKHeLp3mdWZ8Wux8f84ol+cFjx49Jw+GLd+c/yk7mO6+Ev4yZv9cYVuUQj A1euek9lCm4K6w6g7Tfvfvg0lm62JmhEf7QjygtRN0iVj4UIvVDjcI45gnSGMAs4aUIh gp53ekBi1N2ukLhqFhdUPqB/hd+6FVKFs/QELMFej9Y/fZyNP1i7NTzeQ1UtYNYHenLR 5wxGUSo6S77a9oc0qDIh2AJ1+MQrP10JlsEFuKEmoWAm5x8ZAZJHeWNvVTbAHZgfJfg2 EiIA== X-Gm-Message-State: AIVw1111RKMbNcSY+eYbDlSBgqFk4fO+SUlDFWNxIG7d1w1UyGS9rBN5 ssyoKRQM6rW+UA== X-Received: by 10.98.65.220 with SMTP id g89mr4956530pfd.122.1501915107495; Fri, 04 Aug 2017 23:38:27 -0700 (PDT) Received: from dhcp-whq-twvpn-3-vpnpool-10-159-238-106.vpn.oracle.com (c-69-181-250-163.hsd1.ca.comcast.net. [69.181.250.163]) by smtp.gmail.com with ESMTPSA id j124sm6131387pfc.78.2017.08.04.23.38.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Aug 2017 23:38:27 -0700 (PDT) From: Yinghai Lu To: Bjorn Helgaas Cc: Linus Torvalds , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH 02/10] PCI: introduce ioport_res/iomem_res for PCI_TEST Date: Fri, 4 Aug 2017 23:37:53 -0700 Message-Id: <20170805063801.15880-3-yinghai@kernel.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170805063801.15880-1-yinghai@kernel.org> References: <20170805063801.15880-1-yinghai@kernel.org> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make every bus to take the pointer to correct iomem_res instead of using iomem_resource directly. So PCI_TEST could use different iomem_res later. Signed-off-by: Yinghai Lu --- drivers/pci/probe.c | 2 ++ drivers/pci/quirks.c | 2 +- drivers/pci/setup-bus.c | 2 +- drivers/pci/setup-res.c | 4 ++-- include/linux/pci.h | 13 +++++++++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index c31310d..1811016 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -881,6 +881,8 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent, child->msi = parent->msi; child->sysdata = parent->sysdata; child->bus_flags = parent->bus_flags; + child->iomem_res = parent->iomem_res; + child->ioport_res = parent->ioport_res; /* initialize some portions of the bus device, but don't register it * now as the parent is not properly set up yet. diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 6967c6b..dc31098 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -1617,7 +1617,7 @@ static void quirk_alder_ioapic(struct pci_dev *pdev) * not touch this (and it's already covered by the fixmap), so * forcibly insert it into the resource tree */ if (pci_resource_start(pdev, 0) && pci_resource_len(pdev, 0)) - insert_resource(&iomem_resource, &pdev->resource[0]); + insert_resource(iomem_res(pdev->bus), &pdev->resource[0]); /* The next five BARs all seem to be rubbish, so just clean * them out */ diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 958da7d..1c30102 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -805,7 +805,7 @@ static struct resource *find_free_bus_resource(struct pci_bus *bus, struct resource *r; pci_bus_for_each_resource(bus, r, i) { - if (r == &ioport_resource || r == &iomem_resource) + if (r == ioport_res(bus) || r == iomem_res(bus)) continue; if (r && (r->flags & type_mask) == type && !r->parent) return r; diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 85774b7..43921a4 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -215,9 +215,9 @@ static int pci_revert_fw_address(struct resource *res, struct pci_dev *dev, root = pci_find_parent_resource(dev, res); if (!root) { if (res->flags & IORESOURCE_IO) - root = &ioport_resource; + root = ioport_res(dev->bus); else - root = &iomem_resource; + root = iomem_res(dev->bus); } dev_info(&dev->dev, "BAR %d: trying firmware assignment %pR\n", diff --git a/include/linux/pci.h b/include/linux/pci.h index 4869e66..c58a635 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -524,6 +524,9 @@ struct pci_bus { void *sysdata; /* hook for sys-specific extension */ struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */ + struct resource *iomem_res; /* pointer to root iomem_resource */ + struct resource *ioport_res; /* pointer to root ioport_resource */ + unsigned char number; /* bus number */ unsigned char primary; /* number of primary bridge */ unsigned char max_bus_speed; /* enum pci_bus_speed */ @@ -545,6 +548,16 @@ struct pci_bus { #define to_pci_bus(n) container_of(n, struct pci_bus, dev) +static inline struct resource *iomem_res(struct pci_bus *bus) +{ + return bus->iomem_res ? : &iomem_resource; +} + +static inline struct resource *ioport_res(struct pci_bus *bus) +{ + return bus->ioport_res ? : &ioport_resource; +} + /* * Returns true if the PCI bus is root (behind host-PCI bridge), * false otherwise