Skip to content

Commit 7f10074

Browse files
Vidya Sagarbjorn-helgaas
authored andcommitted
PCI: tegra: Add Tegra194 MCFG quirks for ECAM errata
The PCIe controller in Tegra194 SoC is not ECAM-compliant. With the current hardware design, ECAM can be enabled only for one controller (the C5 controller) with bus numbers starting from 160 instead of 0. A different approach is taken to avoid this abnormal way of enabling ECAM for just one controller but to enable configuration space access for all the other controllers. In this approach, ops are added through MCFG quirk mechanism which access the configuration spaces by dynamically programming iATU (internal AddressTranslation Unit) to generate respective configuration accesses just like the way it is done in DesignWare core sub-system. This issue is specific to Tegra194 and it would be fixed in the future generations of Tegra SoCs. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vidya Sagar <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent a38fd87 commit 7f10074

File tree

4 files changed

+111
-1
lines changed

4 files changed

+111
-1
lines changed

drivers/acpi/pci_mcfg.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ static struct mcfg_fixup mcfg_quirks[] = {
116116
THUNDER_ECAM_QUIRK(2, 12),
117117
THUNDER_ECAM_QUIRK(2, 13),
118118

119+
{ "NVIDIA", "TEGRA194", 1, 0, MCFG_BUS_ANY, &tegra194_pcie_ops},
120+
{ "NVIDIA", "TEGRA194", 1, 1, MCFG_BUS_ANY, &tegra194_pcie_ops},
121+
{ "NVIDIA", "TEGRA194", 1, 2, MCFG_BUS_ANY, &tegra194_pcie_ops},
122+
{ "NVIDIA", "TEGRA194", 1, 3, MCFG_BUS_ANY, &tegra194_pcie_ops},
123+
{ "NVIDIA", "TEGRA194", 1, 4, MCFG_BUS_ANY, &tegra194_pcie_ops},
124+
{ "NVIDIA", "TEGRA194", 1, 5, MCFG_BUS_ANY, &tegra194_pcie_ops},
125+
119126
#define XGENE_V1_ECAM_MCFG(rev, seg) \
120127
{"APM ", "XGENE ", rev, seg, MCFG_BUS_ANY, \
121128
&xgene_v1_pcie_ecam_ops }

drivers/pci/controller/dwc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ obj-$(CONFIG_PCIE_INTEL_GW) += pcie-intel-gw.o
1717
obj-$(CONFIG_PCIE_KIRIN) += pcie-kirin.o
1818
obj-$(CONFIG_PCIE_HISI_STB) += pcie-histb.o
1919
obj-$(CONFIG_PCI_MESON) += pci-meson.o
20-
obj-$(CONFIG_PCIE_TEGRA194) += pcie-tegra194.o
2120
obj-$(CONFIG_PCIE_UNIPHIER) += pcie-uniphier.o
2221
obj-$(CONFIG_PCIE_UNIPHIER_EP) += pcie-uniphier-ep.o
2322

@@ -34,4 +33,5 @@ obj-$(CONFIG_PCIE_UNIPHIER_EP) += pcie-uniphier-ep.o
3433
ifdef CONFIG_PCI
3534
obj-$(CONFIG_ARM64) += pcie-al.o
3635
obj-$(CONFIG_ARM64) += pcie-hisi.o
36+
obj-$(CONFIG_ARM64) += pcie-tegra194.o
3737
endif

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

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <linux/of_irq.h>
2323
#include <linux/of_pci.h>
2424
#include <linux/pci.h>
25+
#include <linux/pci-acpi.h>
26+
#include <linux/pci-ecam.h>
2527
#include <linux/phy/phy.h>
2628
#include <linux/pinctrl/consumer.h>
2729
#include <linux/platform_device.h>
@@ -311,6 +313,104 @@ struct tegra_pcie_dw_of_data {
311313
enum dw_pcie_device_mode mode;
312314
};
313315

316+
#if defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS)
317+
struct tegra194_pcie_ecam {
318+
void __iomem *config_base;
319+
void __iomem *iatu_base;
320+
void __iomem *dbi_base;
321+
};
322+
323+
static int tegra194_acpi_init(struct pci_config_window *cfg)
324+
{
325+
struct device *dev = cfg->parent;
326+
struct tegra194_pcie_ecam *pcie_ecam;
327+
328+
pcie_ecam = devm_kzalloc(dev, sizeof(*pcie_ecam), GFP_KERNEL);
329+
if (!pcie_ecam)
330+
return -ENOMEM;
331+
332+
pcie_ecam->config_base = cfg->win;
333+
pcie_ecam->iatu_base = cfg->win + SZ_256K;
334+
pcie_ecam->dbi_base = cfg->win + SZ_512K;
335+
cfg->priv = pcie_ecam;
336+
337+
return 0;
338+
}
339+
340+
static void atu_reg_write(struct tegra194_pcie_ecam *pcie_ecam, int index,
341+
u32 val, u32 reg)
342+
{
343+
u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index);
344+
345+
writel(val, pcie_ecam->iatu_base + offset + reg);
346+
}
347+
348+
static void program_outbound_atu(struct tegra194_pcie_ecam *pcie_ecam,
349+
int index, int type, u64 cpu_addr,
350+
u64 pci_addr, u64 size)
351+
{
352+
atu_reg_write(pcie_ecam, index, lower_32_bits(cpu_addr),
353+
PCIE_ATU_LOWER_BASE);
354+
atu_reg_write(pcie_ecam, index, upper_32_bits(cpu_addr),
355+
PCIE_ATU_UPPER_BASE);
356+
atu_reg_write(pcie_ecam, index, lower_32_bits(pci_addr),
357+
PCIE_ATU_LOWER_TARGET);
358+
atu_reg_write(pcie_ecam, index, lower_32_bits(cpu_addr + size - 1),
359+
PCIE_ATU_LIMIT);
360+
atu_reg_write(pcie_ecam, index, upper_32_bits(pci_addr),
361+
PCIE_ATU_UPPER_TARGET);
362+
atu_reg_write(pcie_ecam, index, type, PCIE_ATU_CR1);
363+
atu_reg_write(pcie_ecam, index, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
364+
}
365+
366+
static void __iomem *tegra194_map_bus(struct pci_bus *bus,
367+
unsigned int devfn, int where)
368+
{
369+
struct pci_config_window *cfg = bus->sysdata;
370+
struct tegra194_pcie_ecam *pcie_ecam = cfg->priv;
371+
u32 busdev;
372+
int type;
373+
374+
if (bus->number < cfg->busr.start || bus->number > cfg->busr.end)
375+
return NULL;
376+
377+
if (bus->number == cfg->busr.start) {
378+
if (PCI_SLOT(devfn) == 0)
379+
return pcie_ecam->dbi_base + where;
380+
else
381+
return NULL;
382+
}
383+
384+
busdev = PCIE_ATU_BUS(bus->number) | PCIE_ATU_DEV(PCI_SLOT(devfn)) |
385+
PCIE_ATU_FUNC(PCI_FUNC(devfn));
386+
387+
if (bus->parent->number == cfg->busr.start) {
388+
if (PCI_SLOT(devfn) == 0)
389+
type = PCIE_ATU_TYPE_CFG0;
390+
else
391+
return NULL;
392+
} else {
393+
type = PCIE_ATU_TYPE_CFG1;
394+
}
395+
396+
program_outbound_atu(pcie_ecam, 0, type, cfg->res.start, busdev,
397+
SZ_256K);
398+
399+
return pcie_ecam->config_base + where;
400+
}
401+
402+
const struct pci_ecam_ops tegra194_pcie_ops = {
403+
.init = tegra194_acpi_init,
404+
.pci_ops = {
405+
.map_bus = tegra194_map_bus,
406+
.read = pci_generic_config_read,
407+
.write = pci_generic_config_write,
408+
}
409+
};
410+
#endif /* defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS) */
411+
412+
#ifdef CONFIG_PCIE_TEGRA194
413+
314414
static inline struct tegra_pcie_dw *to_tegra_pcie(struct dw_pcie *pci)
315415
{
316416
return container_of(pci, struct tegra_pcie_dw, pci);
@@ -2311,3 +2411,5 @@ MODULE_DEVICE_TABLE(of, tegra_pcie_dw_of_match);
23112411
MODULE_AUTHOR("Vidya Sagar <[email protected]>");
23122412
MODULE_DESCRIPTION("NVIDIA PCIe host controller driver");
23132413
MODULE_LICENSE("GPL v2");
2414+
2415+
#endif /* CONFIG_PCIE_TEGRA194 */

include/linux/pci-ecam.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ extern const struct pci_ecam_ops pci_thunder_ecam_ops; /* Cavium ThunderX 1.x */
8585
extern const struct pci_ecam_ops xgene_v1_pcie_ecam_ops; /* APM X-Gene PCIe v1 */
8686
extern const struct pci_ecam_ops xgene_v2_pcie_ecam_ops; /* APM X-Gene PCIe v2.x */
8787
extern const struct pci_ecam_ops al_pcie_ops; /* Amazon Annapurna Labs PCIe */
88+
extern const struct pci_ecam_ops tegra194_pcie_ops; /* Tegra194 PCIe */
8889
#endif
8990

9091
#if IS_ENABLED(CONFIG_PCI_HOST_COMMON)

0 commit comments

Comments
 (0)