From patchwork Fri Sep 11 23:21:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Daney X-Patchwork-Id: 7165641 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5AF42BF036 for ; Fri, 11 Sep 2015 23:24:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5DFC5207E6 for ; Fri, 11 Sep 2015 23:24:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 20F43206EC for ; Fri, 11 Sep 2015 23:24:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755963AbbIKXX6 (ORCPT ); Fri, 11 Sep 2015 19:23:58 -0400 Received: from mail-ig0-f179.google.com ([209.85.213.179]:35195 "EHLO mail-ig0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754420AbbIKXWI (ORCPT ); Fri, 11 Sep 2015 19:22:08 -0400 Received: by igbkq10 with SMTP id kq10so52821023igb.0; Fri, 11 Sep 2015 16:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dGmWrfACmGuok3Qi0ceeT6vhCz/Dnew3girtz77X2DU=; b=iAZc9ose/cptl4qI/zk7vsvEy29BKh/umuLly4//Tie10b7CGa+0vJCXxfUKzVdTbQ VEGWSygtUw/UyVUEo1FbTWpJPyNOda0mAkyZLf06GeFOIdtPY7Fmf5sUpd6cjYHNbY7x JJ3ARzObYgI5Hwi61CILGiSKgj+4rT3BLn02ri27y+A+INcsXJraR+tnLSRzr2ihCf/G 37xsqg7r+Zaof/0StQmO+xD5emwRSkxrSbvwJ95bCupxImhZlGkH699BSbKaC0OAu41C yClRqFwkOxhmtravPzPiZ0ipsdRNb7CS06zDBm2WKi9QR5irQ/UhioraBEhACojd8Z7z 9DsA== X-Received: by 10.50.112.168 with SMTP id ir8mr1065294igb.6.1442013727408; Fri, 11 Sep 2015 16:22:07 -0700 (PDT) Received: from dl.caveonetworks.com (64.2.3.194.ptr.us.xo.net. [64.2.3.194]) by smtp.gmail.com with ESMTPSA id 3sm662789igy.10.2015.09.11.16.22.04 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 11 Sep 2015 16:22:04 -0700 (PDT) Received: from dl.caveonetworks.com (localhost.localdomain [127.0.0.1]) by dl.caveonetworks.com (8.14.5/8.14.5) with ESMTP id t8BNM3FC005054; Fri, 11 Sep 2015 16:22:03 -0700 Received: (from ddaney@localhost) by dl.caveonetworks.com (8.14.5/8.14.5/Submit) id t8BNM38e005053; Fri, 11 Sep 2015 16:22:03 -0700 From: David Daney To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Herring , Frank Rowand , Grant Likely , Bjorn Helgaas , linux-pci@vger.kernel.org, Will Deacon , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , linux-arm-kernel@lists.infradead.org Cc: David Daney Subject: [PATCH 3/6] PCI: generic: Quit clobbering our pci_ops. Date: Fri, 11 Sep 2015 16:21:56 -0700 Message-Id: <1442013719-5001-4-git-send-email-ddaney.cavm@gmail.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1442013719-5001-1-git-send-email-ddaney.cavm@gmail.com> References: <1442013719-5001-1-git-send-email-ddaney.cavm@gmail.com> 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, 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 From: David Daney The pci-host-generic driver keeps a global struct pci_ops which it then patches with the .map_bus method appropriate for the bus device. A problem arises when the driver is used for two different types of bus devices, the .map_bus method for the last device probed clobbers the method for all previous devices. The result, only the last bus device probed has the proper .map_bus, and the others fail. Move the struct pci_ops into the bus specific structure, and initialize it when the bus device is probed. Keep a copy of the gen_pci_cfg_bus_ops structure, instead of a pointer to a global copy, to future proof against the addition of bus specific elements to struct pci_ops. Signed-off-by: David Daney --- drivers/pci/host/pci-host-generic.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/pci/host/pci-host-generic.c b/drivers/pci/host/pci-host-generic.c index a0fb241..cd6f898 100644 --- a/drivers/pci/host/pci-host-generic.c +++ b/drivers/pci/host/pci-host-generic.c @@ -27,7 +27,7 @@ struct gen_pci_cfg_bus_ops { u32 bus_shift; - void __iomem *(*map_bus)(struct pci_bus *, unsigned int, int); + struct pci_ops ops; }; struct gen_pci_cfg_windows { @@ -35,7 +35,7 @@ struct gen_pci_cfg_windows { struct resource *bus_range; void __iomem **win; - const struct gen_pci_cfg_bus_ops *ops; + struct gen_pci_cfg_bus_ops ops; }; /* @@ -65,7 +65,11 @@ static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus, static struct gen_pci_cfg_bus_ops gen_pci_cfg_cam_bus_ops = { .bus_shift = 16, - .map_bus = gen_pci_map_cfg_bus_cam, + .ops = { + .map_bus = gen_pci_map_cfg_bus_cam, + .read = pci_generic_config_read, + .write = pci_generic_config_write, + } }; static void __iomem *gen_pci_map_cfg_bus_ecam(struct pci_bus *bus, @@ -80,12 +84,11 @@ static void __iomem *gen_pci_map_cfg_bus_ecam(struct pci_bus *bus, static struct gen_pci_cfg_bus_ops gen_pci_cfg_ecam_bus_ops = { .bus_shift = 20, - .map_bus = gen_pci_map_cfg_bus_ecam, -}; - -static struct pci_ops gen_pci_ops = { - .read = pci_generic_config_read, - .write = pci_generic_config_write, + .ops = { + .map_bus = gen_pci_map_cfg_bus_ecam, + .read = pci_generic_config_read, + .write = pci_generic_config_write, + } }; static const struct of_device_id gen_pci_of_match[] = { @@ -175,7 +178,7 @@ static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci) /* Limit the bus-range to fit within reg */ bus_max = pci->cfg.bus_range->start + - (resource_size(&pci->cfg.res) >> pci->cfg.ops->bus_shift) - 1; + (resource_size(&pci->cfg.res) >> pci->cfg.ops.bus_shift) - 1; pci->cfg.bus_range->end = min_t(resource_size_t, pci->cfg.bus_range->end, bus_max); @@ -193,7 +196,7 @@ static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci) bus_range = pci->cfg.bus_range; for (busn = bus_range->start; busn <= bus_range->end; ++busn) { u32 idx = busn - bus_range->start; - u32 sz = 1 << pci->cfg.ops->bus_shift; + u32 sz = 1 << pci->cfg.ops.bus_shift; pci->cfg.win[idx] = devm_ioremap(dev, pci->cfg.res.start + busn * sz, @@ -240,8 +243,7 @@ static int gen_pci_probe(struct platform_device *pdev) } of_id = of_match_node(gen_pci_of_match, np); - pci->cfg.ops = of_id->data; - gen_pci_ops.map_bus = pci->cfg.ops->map_bus; + pci->cfg.ops = *(struct gen_pci_cfg_bus_ops *)of_id->data; pci->host.dev.parent = dev; INIT_LIST_HEAD(&pci->host.windows); INIT_LIST_HEAD(&pci->resources); @@ -262,7 +264,8 @@ static int gen_pci_probe(struct platform_device *pdev) if (!pci_has_flag(PCI_PROBE_ONLY)) pci_add_flags(PCI_REASSIGN_ALL_RSRC | PCI_REASSIGN_ALL_BUS); - bus = pci_scan_root_bus(dev, 0, &gen_pci_ops, pci, &pci->resources); + bus = pci_scan_root_bus(dev, 0, + &pci->cfg.ops.ops, pci, &pci->resources); if (!bus) { dev_err(dev, "Scanning rootbus failed"); return -ENODEV;