Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3214603yba; Tue, 16 Apr 2019 07:03:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUWKIDhY5kYKmYCmVacdfy5CQ0lvbgE0xF4TEM99mHEKe0Ra02+NzScfuWWdiAqwftdaKZ X-Received: by 2002:a17:902:a704:: with SMTP id w4mr79322344plq.51.1555423392766; Tue, 16 Apr 2019 07:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555423392; cv=none; d=google.com; s=arc-20160816; b=q7/lU00Nm6/5jdAGyQnPajP/K9pFHIG8BMluAxFHjWrNAXIcL48cIiKtFz7GVsvFau m5V3qSUyaJwlfdw4X30UeZO8QXDVlXQ5bjhaku1AeEDknoY9iFhorBFVIFTRkmJCOhU3 vvR0bQbNDemIPXU36Ybi8nbPAUWQfimlmvB3Z1jdoZ1mpEzpke33RBiNchxeHRkwCIMC uHm9j2wEYd0FJaikHghAKLmQnJVBhPeINYCa5V+298scskhQCaMgeiSgmnBiCS20OpZI bpKbBltg7APE1cI4/iMyuwmN/iaYCgMNOL/hay0nHbyaPhlA/hKi96Ky+e3SH9h2N4VZ 9xpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=VQJqGUcq/LXj0pTqLXNQOdyjdftj74cS+7rH7xwQI1c=; b=DiK72tds33QSMEMJKboJRgkswuuNXkMVcKtxpir6Tj+wnYs9BkqaaDsBK085sppkJ6 hIZmZsT9T2N4xwSKi+FRAnIkYceY9f72nmcvJGjQyxpdDeYE3CTWFDtJLYl1ofTkABbu WOsNczlaaFqPYJ3hmp16MCOVJFrALtwpid0TokB47mcnYAw/OKAWks1K1uP/zhg7EklM cAfTeYb5XsUBOwxZBbwKHULAnXGgYJ4A7sUV0Z06z7op7TFk2DJXJxsw3ytUAazONe9L IybojIgNTf81WEe+FWALyWI2lh7aOqHN+AfdS1OD46Rh3ptZZ5e7WLzKR20deaaHq7rO eVqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11si46441373pgp.391.2019.04.16.07.02.54; Tue, 16 Apr 2019 07:03:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729103AbfDPOBq (ORCPT + 99 others); Tue, 16 Apr 2019 10:01:46 -0400 Received: from foss.arm.com ([217.140.101.70]:55796 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726500AbfDPOBq (ORCPT ); Tue, 16 Apr 2019 10:01:46 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A337CEBD; Tue, 16 Apr 2019 07:01:45 -0700 (PDT) Received: from red-moon (unknown [10.1.197.39]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 255073F59C; Tue, 16 Apr 2019 07:01:43 -0700 (PDT) Date: Tue, 16 Apr 2019 15:01:44 +0100 From: Lorenzo Pieralisi To: Jonathan Chocron , bhelgaas@google.com Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, vaerov@amazon.com, dwmw@amazon.co.uk, benh@kernel.crashing.org, alisaidi@amazon.com, zeev@amazon.com, ronenk@amazon.com, barakw@amazon.com, talel@amazon.com, hanochu@amazon.com, hhhawa@amazon.com Subject: Re: [PATCH v3] PCI: al: Add Amazon Annapurna Labs PCIe host controller driver Message-ID: <20190416140144.GB14705@red-moon> References: <20190326125508.GG24180@google.com> <1553774276-24675-1-git-send-email-jonnyc@amazon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1553774276-24675-1-git-send-email-jonnyc@amazon.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 28, 2019 at 01:57:56PM +0200, Jonathan Chocron wrote: > Add support for Amazon's Annapurna Labs PCIe driver. The HW controller > is based on DesignWare's IP. > > The HW doesn't support accessing the Root Port's config space via ECAM, > so we obtain its base address via an AMZN0001 device. > > Furthermore, the DesignWare PCIe controller doesn't filter out config > transactions sent to devices 1 and up on its bus, so they are filtered > by the driver. > > All subordinate buses do support ECAM access. > > Implementing specific PCI config access functions involves: > - Adding an init function to obtain the Root Port's base address from > an AMZN0001 device. > - Adding a new entry in the MCFG quirk array > > Co-developed-by: Vladimir Aerov > Signed-off-by: Jonathan Chocron > Signed-off-by: Vladimir Aerov > Reviewed-by: David Woodhouse > --- > > --v2: > - Fix commit message comments (incl. using AMZN0001 instead of > PNP0C02) > - Use the usual multi-line comment style > > --v3: > - Fix additional commit message comments > > MAINTAINERS | 6 +++ > drivers/acpi/pci_mcfg.c | 12 +++++ > drivers/pci/controller/dwc/Makefile | 1 + > drivers/pci/controller/dwc/pcie-al.c | 93 ++++++++++++++++++++++++++++++++++++ > include/linux/pci-ecam.h | 1 + > 5 files changed, 113 insertions(+) > create mode 100644 drivers/pci/controller/dwc/pcie-al.c I think Bjorn can take this if he is OK with it, it is not really necessary to queue it via the controller/dwc tree so: Acked-by: Lorenzo Pieralisi > diff --git a/MAINTAINERS b/MAINTAINERS > index 32d444476a90..7a17017f9f82 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -11769,6 +11769,12 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/pci.git/ > S: Supported > F: drivers/pci/controller/ > > +PCIE DRIVER FOR ANNAPURNA LABS > +M: Jonathan Chocron > +L: linux-pci@vger.kernel.org > +S: Maintained > +F: drivers/pci/controller/dwc/pcie-al.c > + > PCIE DRIVER FOR AMLOGIC MESON > M: Yue Wang > L: linux-pci@vger.kernel.org > diff --git a/drivers/acpi/pci_mcfg.c b/drivers/acpi/pci_mcfg.c > index a4e8432fc2fb..b42be067fb83 100644 > --- a/drivers/acpi/pci_mcfg.c > +++ b/drivers/acpi/pci_mcfg.c > @@ -52,6 +52,18 @@ struct mcfg_fixup { > static struct mcfg_fixup mcfg_quirks[] = { > /* { OEM_ID, OEM_TABLE_ID, REV, SEGMENT, BUS_RANGE, ops, cfgres }, */ > > +#define AL_ECAM(table_id, rev, seg, ops) \ > + { "AMAZON", table_id, rev, seg, MCFG_BUS_ANY, ops } > + > + AL_ECAM("GRAVITON", 0, 0, &al_pcie_ops), > + AL_ECAM("GRAVITON", 0, 1, &al_pcie_ops), > + AL_ECAM("GRAVITON", 0, 2, &al_pcie_ops), > + AL_ECAM("GRAVITON", 0, 3, &al_pcie_ops), > + AL_ECAM("GRAVITON", 0, 4, &al_pcie_ops), > + AL_ECAM("GRAVITON", 0, 5, &al_pcie_ops), > + AL_ECAM("GRAVITON", 0, 6, &al_pcie_ops), > + AL_ECAM("GRAVITON", 0, 7, &al_pcie_ops), > + > #define QCOM_ECAM32(seg) \ > { "QCOM ", "QDF2432 ", 1, seg, MCFG_BUS_ANY, &pci_32b_ops } > > diff --git a/drivers/pci/controller/dwc/Makefile b/drivers/pci/controller/dwc/Makefile > index 7bcdcdf5024e..1ea773c0070d 100644 > --- a/drivers/pci/controller/dwc/Makefile > +++ b/drivers/pci/controller/dwc/Makefile > @@ -28,5 +28,6 @@ obj-$(CONFIG_PCIE_UNIPHIER) += pcie-uniphier.o > # depending on whether ACPI, the DT driver, or both are enabled. > > ifdef CONFIG_PCI > +obj-$(CONFIG_ARM64) += pcie-al.o > obj-$(CONFIG_ARM64) += pcie-hisi.o > endif > diff --git a/drivers/pci/controller/dwc/pcie-al.c b/drivers/pci/controller/dwc/pcie-al.c > new file mode 100644 > index 000000000000..65a9776c12be > --- /dev/null > +++ b/drivers/pci/controller/dwc/pcie-al.c > @@ -0,0 +1,93 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * PCIe host controller driver for Amazon's Annapurna Labs IP (used in chips > + * such as Graviton and Alpine) > + * > + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. > + * > + * Author: Jonathan Chocron > + */ > + > +#include > +#include > +#include > +#include "../../pci.h" > + > +#if defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS) > + > +struct al_pcie_acpi { > + void __iomem *dbi_base; > +}; > + > +static void __iomem *al_pcie_map_bus(struct pci_bus *bus, unsigned int devfn, > + int where) > +{ > + struct pci_config_window *cfg = bus->sysdata; > + struct al_pcie_acpi *pcie = cfg->priv; > + void __iomem *dbi_base = pcie->dbi_base; > + > + if (bus->number == cfg->busr.start) { > + /* > + * The DW PCIe core doesn't filter out transactions to other > + * devices/functions on the primary bus num, so we do this here. > + */ > + if (PCI_SLOT(devfn) > 0) > + return NULL; > + else > + return dbi_base + where; > + } > + > + return pci_ecam_map_bus(bus, devfn, where); > +} > + > +static int al_pcie_init(struct pci_config_window *cfg) > +{ > + struct device *dev = cfg->parent; > + struct acpi_device *adev = to_acpi_device(dev); > + struct acpi_pci_root *root = acpi_driver_data(adev); > + struct al_pcie_acpi *al_pcie; > + struct resource *res; > + int ret; > + > + al_pcie = devm_kzalloc(dev, sizeof(*al_pcie), GFP_KERNEL); > + if (!al_pcie) > + return -ENOMEM; > + > + res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL); > + if (!res) > + return -ENOMEM; > + > + ret = acpi_get_rc_resources(dev, "AMZN0001", root->segment, res); > + if (ret) { > + dev_err(dev, "can't get rc dbi base address for SEG %d\n", > + root->segment); > + return ret; > + } > + > + dev_dbg(dev, "Root port dbi res: %pR\n", res); > + > + al_pcie->dbi_base = devm_pci_remap_cfg_resource(dev, res); > + if (IS_ERR(al_pcie->dbi_base)) { > + long err = PTR_ERR(al_pcie->dbi_base); > + > + dev_err(dev, "couldn't remap dbi base %pR (err:%ld)\n", > + res, err); > + return err; > + } > + > + cfg->priv = al_pcie; > + > + return 0; > +} > + > +struct pci_ecam_ops al_pcie_ops = { > + .bus_shift = 20, > + .init = al_pcie_init, > + .pci_ops = { > + .map_bus = al_pcie_map_bus, > + .read = pci_generic_config_read, > + .write = pci_generic_config_write, > + } > +}; > + > +#endif /* defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS) */ > diff --git a/include/linux/pci-ecam.h b/include/linux/pci-ecam.h > index 29efa09d686b..a73164c85e78 100644 > --- a/include/linux/pci-ecam.h > +++ b/include/linux/pci-ecam.h > @@ -56,6 +56,7 @@ void __iomem *pci_ecam_map_bus(struct pci_bus *bus, unsigned int devfn, > extern struct pci_ecam_ops pci_thunder_ecam_ops; /* Cavium ThunderX 1.x */ > extern struct pci_ecam_ops xgene_v1_pcie_ecam_ops; /* APM X-Gene PCIe v1 */ > extern struct pci_ecam_ops xgene_v2_pcie_ecam_ops; /* APM X-Gene PCIe v2.x */ > +extern struct pci_ecam_ops al_pcie_ops; /* Amazon Annapurna Labs PCIe */ > #endif > > #ifdef CONFIG_PCI_HOST_COMMON > -- > 1.9.1 >