Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3205014img; Mon, 25 Mar 2019 06:00:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTALkHf30uK2Q9K0NERLJrK4DC1hNcp7chD6hzcWk9yyMOApp3yEm4yZjNotzMrf9N4fAe X-Received: by 2002:aa7:920b:: with SMTP id 11mr23116853pfo.3.1553518845811; Mon, 25 Mar 2019 06:00:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553518845; cv=none; d=google.com; s=arc-20160816; b=0V1gvEpHOvcBdJ968U1qUWj8OC7ATPvZTbG2s1EH9CLE9KV2LSZvdeJUX6WrvD6TTW fGxVopVqQp033vOMOtHnPb6JXlsvE3dg5eiz+75HJNvS/hKRYdCkoMWPEPtM5RC1nAMJ GFxgXs8tPsPYNlI+6z9eiiIUTB/QOAFRTV44cNiz28ReYr9pbjozgFXlOn49ApfXg5ji 5TPH8W0SVdAFPO9STo88ZPtRUT3yqojP5UmAGVgJKgD2tPyI+u22QetY2xguyPFdmfZV 0eZuM7NlN4pOncH/gKexB5WsIVSACdUo2TU1fDxycVLpmCikY+Gb/5K+g/4MwHM5hcSJ 1PLg== 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:dkim-signature; bh=gHzb9rveGGpVMahhncGc7vlyo7gq5HdfBRyHW2QFOuw=; b=rNFwr03qFMrswfKLuZtC8IjsV1C96HeHSsZPCFMeip2v0foWNkRP9LmRNrkYEb3Ga4 tpd5bJaH7XMvyWIOH328Ka34bDzXJvKkTkS8IVPbDCFjsSw563pEh3Rt5cA7LVNB0aVr /kJvwo9Q4E4Lw3kmU8w3/+EnXSgsp6N1oBsKPQ8U5UMR2huGV9HU+VRgobhDDP793D1M tXSRbQFGZ21l4twe0Z9aI4d6Gt/IqGyx/3JsjudrI7iFnjDWVg7KQfgSQWWVou82mOk+ Lcwjyjvw3guvUCcmIt5lRcyNp4VaCzwd4Ut2NPk1iZEWS2gpGEsAvHET5+Dz6AQvtM7B igPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=s74ZNKYA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61si14431691plb.162.2019.03.25.06.00.29; Mon, 25 Mar 2019 06:00:45 -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; dkim=pass header.i=@kernel.org header.s=default header.b=s74ZNKYA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731278AbfCYM6g (ORCPT + 99 others); Mon, 25 Mar 2019 08:58:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:42640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731076AbfCYM6f (ORCPT ); Mon, 25 Mar 2019 08:58:35 -0400 Received: from localhost (173-25-63-173.client.mchsi.com [173.25.63.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2047220823; Mon, 25 Mar 2019 12:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553518714; bh=N83MK0ZwmWb+hiS0Gliv7t5YuZgORyoIMZTA86CXAgY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=s74ZNKYAKC/kbryT3hDlFnBZTW/yn/RgWbE8rWmzuQZBnsrLnBtmX7V41Z3JBbyxS mO/n2G4ySyiTd99YsotiHrUT6TylSzSehR5gtqTi3QYxjnPdAlAX9KHcVSmcUlM2a7 NvTJ1/dKdrb1JwjhTdWBydQwnCSghgpCZ2138ikM= Date: Mon, 25 Mar 2019 07:58:32 -0500 From: Bjorn Helgaas To: jonnyc@amazon.com Cc: linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, 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 Subject: Re: [PATCH] PCI: al: add pcie-al.c Message-ID: <20190325125832.GP251185@google.com> References: <1553512040-4453-1-git-send-email-jonnyc@amazon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1553512040-4453-1-git-send-email-jonnyc@amazon.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jonathan, Looks good to me. Looks like this hardware is sooooo close to Just Working with the generic driver; it's too bad we have to add more ECAM quirks, but sometimes life gives us lemons. Trivial comments below. Lorenzo may have additional comments. The subject should be something like: PCI: al: Add Amazon Annapurna Labs PCIe host controller driver On Mon, Mar 25, 2019 at 01:07:20PM +0200, jonnyc@amazon.com wrote: > From: Jonathan Chocron > > Adding support for Amazon's Annapurna Labs pcie driver. s/pcie/PCIe/ > 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 a PNP0C02 device. s/port's/Port's/ I think you're actually looking for a AMZN0001 device, not a PNP0C02 device. Your firmware might have a PNP0C02 _HID and AMZN0001 _CID, but that's not relevant here since you're only filtering by AMZN0001. > 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. Separate paragraphs with blank lines. > 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 a PNP0C02 device. s/PNP0C02/AMZN0001/ > - 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: Benjamin Herrenschmidt > Reviewed-by: David Woodhouse > --- > MAINTAINERS | 6 +++ > drivers/acpi/pci_mcfg.c | 12 +++++ > drivers/pci/controller/dwc/Makefile | 1 + > drivers/pci/controller/dwc/pcie-al.c | 92 ++++++++++++++++++++++++++++++++++++ > include/linux/pci-ecam.h | 1 + > 5 files changed, 112 insertions(+) > create mode 100644 drivers/pci/controller/dwc/pcie-al.c > > 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..019497c2c714 > --- /dev/null > +++ b/drivers/pci/controller/dwc/pcie-al.c > @@ -0,0 +1,92 @@ > +// 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. > + */ Use usual multi-line comment style: /* * text .. */ > + 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 >