Skip to content

Commit 4166bfe

Browse files
Jonathan Chocronbjorn-helgaas
Jonathan Chocron
authored andcommitted
PCI: al: Add Amazon Annapurna Labs PCIe host controller driver
Add driver for Amazon's Annapurna Labs PCIe host controller. The controller is based on DesignWare's IP. The controller 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. [bhelgaas: Note that there is no Kconfig option for this driver because it is only intended for use with the generic ACPI host bridge driver. This driver is only needed because the DesignWare IP doesn't completely support ECAM access to the root bus.] Link: https://lore.kernel.org/lkml/1553774276-24675-1-git-send-email-jonnyc@amazon.com Co-developed-by: Vladimir Aerov <vaerov@amazon.com> Signed-off-by: Jonathan Chocron <jonnyc@amazon.com> Signed-off-by: Vladimir Aerov <vaerov@amazon.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
1 parent 9e98c67 commit 4166bfe

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

MAINTAINERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12014,6 +12014,12 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/pci.git/
1201412014
S: Supported
1201512015
F: drivers/pci/controller/
1201612016

12017+
PCIE DRIVER FOR ANNAPURNA LABS
12018+
M: Jonathan Chocron <jonnyc@amazon.com>
12019+
L: linux-pci@vger.kernel.org
12020+
S: Maintained
12021+
F: drivers/pci/controller/dwc/pcie-al.c
12022+
1201712023
PCIE DRIVER FOR AMLOGIC MESON
1201812024
M: Yue Wang <yue.wang@Amlogic.com>
1201912025
L: linux-pci@vger.kernel.org

drivers/acpi/pci_mcfg.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ struct mcfg_fixup {
5252
static struct mcfg_fixup mcfg_quirks[] = {
5353
/* { OEM_ID, OEM_TABLE_ID, REV, SEGMENT, BUS_RANGE, ops, cfgres }, */
5454

55+
#define AL_ECAM(table_id, rev, seg, ops) \
56+
{ "AMAZON", table_id, rev, seg, MCFG_BUS_ANY, ops }
57+
58+
AL_ECAM("GRAVITON", 0, 0, &al_pcie_ops),
59+
AL_ECAM("GRAVITON", 0, 1, &al_pcie_ops),
60+
AL_ECAM("GRAVITON", 0, 2, &al_pcie_ops),
61+
AL_ECAM("GRAVITON", 0, 3, &al_pcie_ops),
62+
AL_ECAM("GRAVITON", 0, 4, &al_pcie_ops),
63+
AL_ECAM("GRAVITON", 0, 5, &al_pcie_ops),
64+
AL_ECAM("GRAVITON", 0, 6, &al_pcie_ops),
65+
AL_ECAM("GRAVITON", 0, 7, &al_pcie_ops),
66+
5567
#define QCOM_ECAM32(seg) \
5668
{ "QCOM ", "QDF2432 ", 1, seg, MCFG_BUS_ANY, &pci_32b_ops }
5769

drivers/pci/controller/dwc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ obj-$(CONFIG_PCIE_UNIPHIER) += pcie-uniphier.o
2828
# depending on whether ACPI, the DT driver, or both are enabled.
2929

3030
ifdef CONFIG_PCI
31+
obj-$(CONFIG_ARM64) += pcie-al.o
3132
obj-$(CONFIG_ARM64) += pcie-hisi.o
3233
endif

drivers/pci/controller/dwc/pcie-al.c

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* PCIe host controller driver for Amazon's Annapurna Labs IP (used in chips
4+
* such as Graviton and Alpine)
5+
*
6+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
7+
*
8+
* Author: Jonathan Chocron <jonnyc@amazon.com>
9+
*/
10+
11+
#include <linux/pci.h>
12+
#include <linux/pci-ecam.h>
13+
#include <linux/pci-acpi.h>
14+
#include "../../pci.h"
15+
16+
#if defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS)
17+
18+
struct al_pcie_acpi {
19+
void __iomem *dbi_base;
20+
};
21+
22+
static void __iomem *al_pcie_map_bus(struct pci_bus *bus, unsigned int devfn,
23+
int where)
24+
{
25+
struct pci_config_window *cfg = bus->sysdata;
26+
struct al_pcie_acpi *pcie = cfg->priv;
27+
void __iomem *dbi_base = pcie->dbi_base;
28+
29+
if (bus->number == cfg->busr.start) {
30+
/*
31+
* The DW PCIe core doesn't filter out transactions to other
32+
* devices/functions on the root bus num, so we do this here.
33+
*/
34+
if (PCI_SLOT(devfn) > 0)
35+
return NULL;
36+
else
37+
return dbi_base + where;
38+
}
39+
40+
return pci_ecam_map_bus(bus, devfn, where);
41+
}
42+
43+
static int al_pcie_init(struct pci_config_window *cfg)
44+
{
45+
struct device *dev = cfg->parent;
46+
struct acpi_device *adev = to_acpi_device(dev);
47+
struct acpi_pci_root *root = acpi_driver_data(adev);
48+
struct al_pcie_acpi *al_pcie;
49+
struct resource *res;
50+
int ret;
51+
52+
al_pcie = devm_kzalloc(dev, sizeof(*al_pcie), GFP_KERNEL);
53+
if (!al_pcie)
54+
return -ENOMEM;
55+
56+
res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL);
57+
if (!res)
58+
return -ENOMEM;
59+
60+
ret = acpi_get_rc_resources(dev, "AMZN0001", root->segment, res);
61+
if (ret) {
62+
dev_err(dev, "can't get rc dbi base address for SEG %d\n",
63+
root->segment);
64+
return ret;
65+
}
66+
67+
dev_dbg(dev, "Root port dbi res: %pR\n", res);
68+
69+
al_pcie->dbi_base = devm_pci_remap_cfg_resource(dev, res);
70+
if (IS_ERR(al_pcie->dbi_base)) {
71+
long err = PTR_ERR(al_pcie->dbi_base);
72+
73+
dev_err(dev, "couldn't remap dbi base %pR (err:%ld)\n",
74+
res, err);
75+
return err;
76+
}
77+
78+
cfg->priv = al_pcie;
79+
80+
return 0;
81+
}
82+
83+
struct pci_ecam_ops al_pcie_ops = {
84+
.bus_shift = 20,
85+
.init = al_pcie_init,
86+
.pci_ops = {
87+
.map_bus = al_pcie_map_bus,
88+
.read = pci_generic_config_read,
89+
.write = pci_generic_config_write,
90+
}
91+
};
92+
93+
#endif /* defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS) */

include/linux/pci-ecam.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ extern struct pci_ecam_ops thunder_pem_ecam_ops; /* Cavium ThunderX 1.x & 2.x */
5656
extern struct pci_ecam_ops pci_thunder_ecam_ops; /* Cavium ThunderX 1.x */
5757
extern struct pci_ecam_ops xgene_v1_pcie_ecam_ops; /* APM X-Gene PCIe v1 */
5858
extern struct pci_ecam_ops xgene_v2_pcie_ecam_ops; /* APM X-Gene PCIe v2.x */
59+
extern struct pci_ecam_ops al_pcie_ops; /* Amazon Annapurna Labs PCIe */
5960
#endif
6061

6162
#ifdef CONFIG_PCI_HOST_COMMON

0 commit comments

Comments
 (0)