2018-01-27 01:50:27 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-09-03 06:26:19 +07:00
|
|
|
/*
|
|
|
|
* PCIe host controller driver for Texas Instruments Keystone SoCs
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 Texas Instruments., Ltd.
|
|
|
|
* http://www.ti.com
|
|
|
|
*
|
|
|
|
* Author: Murali Karicheri <m-karicheri2@ti.com>
|
|
|
|
* Implementation based on pci-exynos.c and pcie-designware.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/irqchip/chained_irq.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/delay.h>
|
2016-04-11 21:50:30 +07:00
|
|
|
#include <linux/interrupt.h>
|
2014-09-03 06:26:19 +07:00
|
|
|
#include <linux/irqdomain.h>
|
2016-07-03 06:13:26 +07:00
|
|
|
#include <linux/init.h>
|
2014-09-03 06:26:19 +07:00
|
|
|
#include <linux/msi.h>
|
|
|
|
#include <linux/of_irq.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_pci.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/phy/phy.h>
|
|
|
|
#include <linux/resource.h>
|
|
|
|
#include <linux/signal.h>
|
|
|
|
|
|
|
|
#include "pcie-designware.h"
|
|
|
|
|
|
|
|
#define DRIVER_NAME "keystone-pcie"
|
|
|
|
|
|
|
|
/* DEV_STAT_CTRL */
|
|
|
|
#define PCIE_CAP_BASE 0x70
|
|
|
|
|
2018-10-17 14:40:59 +07:00
|
|
|
/* Application register defines */
|
|
|
|
#define LTSSM_EN_VAL BIT(0)
|
|
|
|
#define LTSSM_STATE_MASK 0x1f
|
|
|
|
#define LTSSM_STATE_L0 0x11
|
|
|
|
#define DBI_CS2_EN_VAL 0x20
|
|
|
|
#define OB_XLAT_EN_VAL 2
|
|
|
|
|
|
|
|
/* Application registers */
|
|
|
|
#define CMD_STATUS 0x004
|
|
|
|
#define CFG_SETUP 0x008
|
|
|
|
#define OB_SIZE 0x030
|
|
|
|
#define CFG_PCIM_WIN_SZ_IDX 3
|
|
|
|
#define CFG_PCIM_WIN_CNT 32
|
|
|
|
#define SPACE0_REMOTE_CFG_OFFSET 0x1000
|
|
|
|
#define OB_OFFSET_INDEX(n) (0x200 + (8 * (n)))
|
|
|
|
#define OB_OFFSET_HI(n) (0x204 + (8 * (n)))
|
|
|
|
|
|
|
|
/* IRQ register defines */
|
|
|
|
#define IRQ_EOI 0x050
|
|
|
|
#define IRQ_STATUS 0x184
|
|
|
|
#define IRQ_ENABLE_SET 0x188
|
|
|
|
#define IRQ_ENABLE_CLR 0x18c
|
|
|
|
|
|
|
|
#define MSI_IRQ 0x054
|
|
|
|
#define MSI0_IRQ_STATUS 0x104
|
|
|
|
#define MSI0_IRQ_ENABLE_SET 0x108
|
|
|
|
#define MSI0_IRQ_ENABLE_CLR 0x10c
|
|
|
|
#define IRQ_STATUS 0x184
|
|
|
|
#define MSI_IRQ_OFFSET 4
|
|
|
|
|
|
|
|
/* Error IRQ bits */
|
|
|
|
#define ERR_AER BIT(5) /* ECRC error */
|
|
|
|
#define ERR_AXI BIT(4) /* AXI tag lookup fatal error */
|
|
|
|
#define ERR_CORR BIT(3) /* Correctable error */
|
|
|
|
#define ERR_NONFATAL BIT(2) /* Non-fatal error */
|
|
|
|
#define ERR_FATAL BIT(1) /* Fatal error */
|
|
|
|
#define ERR_SYS BIT(0) /* System (fatal, non-fatal, or correctable) */
|
|
|
|
#define ERR_IRQ_ALL (ERR_AER | ERR_AXI | ERR_CORR | \
|
|
|
|
ERR_NONFATAL | ERR_FATAL | ERR_SYS)
|
|
|
|
#define ERR_FATAL_IRQ (ERR_FATAL | ERR_AXI)
|
|
|
|
#define ERR_IRQ_STATUS_RAW 0x1c0
|
|
|
|
#define ERR_IRQ_STATUS 0x1c4
|
|
|
|
#define ERR_IRQ_ENABLE_SET 0x1c8
|
|
|
|
#define ERR_IRQ_ENABLE_CLR 0x1cc
|
|
|
|
|
|
|
|
/* Config space registers */
|
|
|
|
#define DEBUG0 0x728
|
|
|
|
|
|
|
|
#define MAX_MSI_HOST_IRQS 8
|
|
|
|
|
2014-09-09 00:03:34 +07:00
|
|
|
/* PCIE controller device IDs */
|
|
|
|
#define PCIE_RC_K2HK 0xb008
|
|
|
|
#define PCIE_RC_K2E 0xb009
|
|
|
|
#define PCIE_RC_K2L 0xb00a
|
2018-10-17 14:40:54 +07:00
|
|
|
#define PCIE_RC_K2G 0xb00b
|
2014-09-09 00:03:34 +07:00
|
|
|
|
2017-02-15 20:18:14 +07:00
|
|
|
#define to_keystone_pcie(x) dev_get_drvdata((x)->dev)
|
2014-09-03 06:26:19 +07:00
|
|
|
|
2018-10-17 14:40:59 +07:00
|
|
|
struct keystone_pcie {
|
|
|
|
struct dw_pcie *pci;
|
|
|
|
struct clk *clk;
|
|
|
|
/* PCI Device ID */
|
|
|
|
u32 device_id;
|
|
|
|
int num_legacy_host_irqs;
|
|
|
|
int legacy_host_irqs[PCI_NUM_INTX];
|
|
|
|
struct device_node *legacy_intc_np;
|
|
|
|
|
|
|
|
int num_msi_host_irqs;
|
|
|
|
int msi_host_irqs[MAX_MSI_HOST_IRQS];
|
|
|
|
struct device_node *msi_intc_np;
|
|
|
|
struct irq_domain *legacy_irq_domain;
|
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
int error_irq;
|
|
|
|
|
|
|
|
/* Application register space */
|
|
|
|
void __iomem *va_app_base; /* DT 1st resource */
|
|
|
|
struct resource app;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void update_reg_offset_bit_pos(u32 offset, u32 *reg_offset,
|
|
|
|
u32 *bit_pos)
|
|
|
|
{
|
|
|
|
*reg_offset = offset % 8;
|
|
|
|
*bit_pos = offset >> 3;
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static phys_addr_t ks_pcie_get_msi_addr(struct pcie_port *pp)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
|
|
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
|
|
|
|
|
|
|
|
return ks_pcie->app.start + MSI_IRQ;
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static u32 ks_pcie_app_readl(struct keystone_pcie *ks_pcie, u32 offset)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
return readl(ks_pcie->va_app_base + offset);
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_app_writel(struct keystone_pcie *ks_pcie, u32 offset,
|
|
|
|
u32 val)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
writel(val, ks_pcie->va_app_base + offset);
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_handle_msi_irq(struct keystone_pcie *ks_pcie, int offset)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
struct dw_pcie *pci = ks_pcie->pci;
|
|
|
|
struct pcie_port *pp = &pci->pp;
|
|
|
|
struct device *dev = pci->dev;
|
|
|
|
u32 pending, vector;
|
|
|
|
int src, virq;
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
pending = ks_pcie_app_readl(ks_pcie, MSI0_IRQ_STATUS + (offset << 4));
|
2018-10-17 14:40:59 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* MSI0 status bit 0-3 shows vectors 0, 8, 16, 24, MSI1 status bit
|
|
|
|
* shows 1, 9, 17, 25 and so forth
|
|
|
|
*/
|
|
|
|
for (src = 0; src < 4; src++) {
|
|
|
|
if (BIT(src) & pending) {
|
|
|
|
vector = offset + (src << 3);
|
|
|
|
virq = irq_linear_revmap(pp->irq_domain, vector);
|
|
|
|
dev_dbg(dev, "irq: bit %d, vector %d, virq %d\n",
|
|
|
|
src, vector, virq);
|
|
|
|
generic_handle_irq(virq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_msi_irq_ack(int irq, struct pcie_port *pp)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
u32 reg_offset, bit_pos;
|
|
|
|
struct keystone_pcie *ks_pcie;
|
|
|
|
struct dw_pcie *pci;
|
|
|
|
|
|
|
|
pci = to_dw_pcie_from_pp(pp);
|
|
|
|
ks_pcie = to_keystone_pcie(pci);
|
|
|
|
update_reg_offset_bit_pos(irq, ®_offset, &bit_pos);
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_app_writel(ks_pcie, MSI0_IRQ_STATUS + (reg_offset << 4),
|
|
|
|
BIT(bit_pos));
|
|
|
|
ks_pcie_app_writel(ks_pcie, IRQ_EOI, reg_offset + MSI_IRQ_OFFSET);
|
2018-10-17 14:40:59 +07:00
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_msi_set_irq(struct pcie_port *pp, int irq)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
u32 reg_offset, bit_pos;
|
|
|
|
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
|
|
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
|
|
|
|
|
|
|
|
update_reg_offset_bit_pos(irq, ®_offset, &bit_pos);
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_app_writel(ks_pcie, MSI0_IRQ_ENABLE_SET + (reg_offset << 4),
|
|
|
|
BIT(bit_pos));
|
2018-10-17 14:40:59 +07:00
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_msi_clear_irq(struct pcie_port *pp, int irq)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
u32 reg_offset, bit_pos;
|
|
|
|
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
|
|
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
|
|
|
|
|
|
|
|
update_reg_offset_bit_pos(irq, ®_offset, &bit_pos);
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_app_writel(ks_pcie, MSI0_IRQ_ENABLE_CLR + (reg_offset << 4),
|
|
|
|
BIT(bit_pos));
|
2018-10-17 14:40:59 +07:00
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static int ks_pcie_msi_host_init(struct pcie_port *pp)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
return dw_pcie_allocate_domains(pp);
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_enable_legacy_irqs(struct keystone_pcie *ks_pcie)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < PCI_NUM_INTX; i++)
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_app_writel(ks_pcie, IRQ_ENABLE_SET + (i << 4), 0x1);
|
2018-10-17 14:40:59 +07:00
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_handle_legacy_irq(struct keystone_pcie *ks_pcie,
|
|
|
|
int offset)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
struct dw_pcie *pci = ks_pcie->pci;
|
|
|
|
struct device *dev = pci->dev;
|
|
|
|
u32 pending;
|
|
|
|
int virq;
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
pending = ks_pcie_app_readl(ks_pcie, IRQ_STATUS + (offset << 4));
|
2018-10-17 14:40:59 +07:00
|
|
|
|
|
|
|
if (BIT(0) & pending) {
|
|
|
|
virq = irq_linear_revmap(ks_pcie->legacy_irq_domain, offset);
|
|
|
|
dev_dbg(dev, ": irq: irq_offset %d, virq %d\n", offset, virq);
|
|
|
|
generic_handle_irq(virq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOI the INTx interrupt */
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_app_writel(ks_pcie, IRQ_EOI, offset);
|
2018-10-17 14:40:59 +07:00
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_enable_error_irq(struct keystone_pcie *ks_pcie)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_app_writel(ks_pcie, ERR_IRQ_ENABLE_SET, ERR_IRQ_ALL);
|
2018-10-17 14:40:59 +07:00
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static irqreturn_t ks_pcie_handle_error_irq(struct keystone_pcie *ks_pcie)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
u32 status;
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
status = ks_pcie_app_readl(ks_pcie, ERR_IRQ_STATUS_RAW) & ERR_IRQ_ALL;
|
2018-10-17 14:40:59 +07:00
|
|
|
if (!status)
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
if (status & ERR_FATAL_IRQ)
|
|
|
|
dev_err(ks_pcie->pci->dev, "fatal error (status %#010x)\n",
|
|
|
|
status);
|
|
|
|
|
|
|
|
/* Ack the IRQ; status bits are RW1C */
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_app_writel(ks_pcie, ERR_IRQ_STATUS, status);
|
2018-10-17 14:40:59 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_ack_legacy_irq(struct irq_data *d)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_mask_legacy_irq(struct irq_data *d)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_unmask_legacy_irq(struct irq_data *d)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static struct irq_chip ks_pcie_legacy_irq_chip = {
|
2018-10-17 14:40:59 +07:00
|
|
|
.name = "Keystone-PCI-Legacy-IRQ",
|
2018-10-17 14:41:01 +07:00
|
|
|
.irq_ack = ks_pcie_ack_legacy_irq,
|
|
|
|
.irq_mask = ks_pcie_mask_legacy_irq,
|
|
|
|
.irq_unmask = ks_pcie_unmask_legacy_irq,
|
2018-10-17 14:40:59 +07:00
|
|
|
};
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static int ks_pcie_init_legacy_irq_map(struct irq_domain *d,
|
|
|
|
unsigned int irq,
|
|
|
|
irq_hw_number_t hw_irq)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
2018-10-17 14:41:01 +07:00
|
|
|
irq_set_chip_and_handler(irq, &ks_pcie_legacy_irq_chip,
|
2018-10-17 14:40:59 +07:00
|
|
|
handle_level_irq);
|
|
|
|
irq_set_chip_data(irq, d->host_data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static const struct irq_domain_ops ks_pcie_legacy_irq_domain_ops = {
|
|
|
|
.map = ks_pcie_init_legacy_irq_map,
|
2018-10-17 14:40:59 +07:00
|
|
|
.xlate = irq_domain_xlate_onetwocell,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2018-10-17 14:41:01 +07:00
|
|
|
* ks_pcie_set_dbi_mode() - Set DBI mode to access overlaid BAR mask
|
2018-10-17 14:40:59 +07:00
|
|
|
* registers
|
|
|
|
*
|
|
|
|
* Since modification of dbi_cs2 involves different clock domain, read the
|
|
|
|
* status back to ensure the transition is complete.
|
|
|
|
*/
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_set_dbi_mode(struct keystone_pcie *ks_pcie)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
val = ks_pcie_app_readl(ks_pcie, CMD_STATUS);
|
|
|
|
ks_pcie_app_writel(ks_pcie, CMD_STATUS, DBI_CS2_EN_VAL | val);
|
2018-10-17 14:40:59 +07:00
|
|
|
|
|
|
|
do {
|
2018-10-17 14:41:01 +07:00
|
|
|
val = ks_pcie_app_readl(ks_pcie, CMD_STATUS);
|
2018-10-17 14:40:59 +07:00
|
|
|
} while (!(val & DBI_CS2_EN_VAL));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-17 14:41:01 +07:00
|
|
|
* ks_pcie_clear_dbi_mode() - Disable DBI mode
|
2018-10-17 14:40:59 +07:00
|
|
|
*
|
|
|
|
* Since modification of dbi_cs2 involves different clock domain, read the
|
|
|
|
* status back to ensure the transition is complete.
|
|
|
|
*/
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_clear_dbi_mode(struct keystone_pcie *ks_pcie)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
val = ks_pcie_app_readl(ks_pcie, CMD_STATUS);
|
|
|
|
ks_pcie_app_writel(ks_pcie, CMD_STATUS, ~DBI_CS2_EN_VAL & val);
|
2018-10-17 14:40:59 +07:00
|
|
|
|
|
|
|
do {
|
2018-10-17 14:41:01 +07:00
|
|
|
val = ks_pcie_app_readl(ks_pcie, CMD_STATUS);
|
2018-10-17 14:40:59 +07:00
|
|
|
} while (val & DBI_CS2_EN_VAL);
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
struct dw_pcie *pci = ks_pcie->pci;
|
|
|
|
struct pcie_port *pp = &pci->pp;
|
|
|
|
u32 start = pp->mem->start, end = pp->mem->end;
|
|
|
|
int i, tr_size;
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
/* Disable BARs for inbound access */
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_set_dbi_mode(ks_pcie);
|
2018-10-17 14:40:59 +07:00
|
|
|
dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0);
|
|
|
|
dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_1, 0);
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_clear_dbi_mode(ks_pcie);
|
2018-10-17 14:40:59 +07:00
|
|
|
|
|
|
|
/* Set outbound translation size per window division */
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_app_writel(ks_pcie, OB_SIZE, CFG_PCIM_WIN_SZ_IDX & 0x7);
|
2018-10-17 14:40:59 +07:00
|
|
|
|
|
|
|
tr_size = (1 << (CFG_PCIM_WIN_SZ_IDX & 0x7)) * SZ_1M;
|
|
|
|
|
|
|
|
/* Using Direct 1:1 mapping of RC <-> PCI memory space */
|
|
|
|
for (i = 0; (i < CFG_PCIM_WIN_CNT) && (start < end); i++) {
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_app_writel(ks_pcie, OB_OFFSET_INDEX(i), start | 1);
|
|
|
|
ks_pcie_app_writel(ks_pcie, OB_OFFSET_HI(i), 0);
|
2018-10-17 14:40:59 +07:00
|
|
|
start += tr_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable OB translation */
|
2018-10-17 14:41:01 +07:00
|
|
|
val = ks_pcie_app_readl(ks_pcie, CMD_STATUS);
|
|
|
|
ks_pcie_app_writel(ks_pcie, CMD_STATUS, OB_XLAT_EN_VAL | val);
|
2018-10-17 14:40:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ks_pcie_cfg_setup() - Set up configuration space address for a device
|
|
|
|
*
|
|
|
|
* @ks_pcie: ptr to keystone_pcie structure
|
|
|
|
* @bus: Bus number the device is residing on
|
|
|
|
* @devfn: device, function number info
|
|
|
|
*
|
|
|
|
* Forms and returns the address of configuration space mapped in PCIESS
|
|
|
|
* address space 0. Also configures CFG_SETUP for remote configuration space
|
|
|
|
* access.
|
|
|
|
*
|
|
|
|
* The address space has two regions to access configuration - local and remote.
|
|
|
|
* We access local region for bus 0 (as RC is attached on bus 0) and remote
|
|
|
|
* region for others with TYPE 1 access when bus > 1. As for device on bus = 1,
|
|
|
|
* we will do TYPE 0 access as it will be on our secondary bus (logical).
|
|
|
|
* CFG_SETUP is needed only for remote configuration access.
|
|
|
|
*/
|
|
|
|
static void __iomem *ks_pcie_cfg_setup(struct keystone_pcie *ks_pcie, u8 bus,
|
|
|
|
unsigned int devfn)
|
|
|
|
{
|
|
|
|
u8 device = PCI_SLOT(devfn), function = PCI_FUNC(devfn);
|
|
|
|
struct dw_pcie *pci = ks_pcie->pci;
|
|
|
|
struct pcie_port *pp = &pci->pp;
|
|
|
|
u32 regval;
|
|
|
|
|
|
|
|
if (bus == 0)
|
|
|
|
return pci->dbi_base;
|
|
|
|
|
|
|
|
regval = (bus << 16) | (device << 8) | function;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since Bus#1 will be a virtual bus, we need to have TYPE0
|
|
|
|
* access only.
|
|
|
|
* TYPE 1
|
|
|
|
*/
|
|
|
|
if (bus != 1)
|
|
|
|
regval |= BIT(24);
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_app_writel(ks_pcie, CFG_SETUP, regval);
|
2018-10-17 14:40:59 +07:00
|
|
|
return pp->va_cfg0_base;
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static int ks_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus,
|
|
|
|
unsigned int devfn, int where, int size,
|
|
|
|
u32 *val)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
|
|
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
|
|
|
|
u8 bus_num = bus->number;
|
|
|
|
void __iomem *addr;
|
|
|
|
|
|
|
|
addr = ks_pcie_cfg_setup(ks_pcie, bus_num, devfn);
|
|
|
|
|
|
|
|
return dw_pcie_read(addr + where, size, val);
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static int ks_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus,
|
|
|
|
unsigned int devfn, int where, int size,
|
|
|
|
u32 val)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
|
|
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
|
|
|
|
u8 bus_num = bus->number;
|
|
|
|
void __iomem *addr;
|
|
|
|
|
|
|
|
addr = ks_pcie_cfg_setup(ks_pcie, bus_num, devfn);
|
|
|
|
|
|
|
|
return dw_pcie_write(addr + where, size, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-17 14:41:01 +07:00
|
|
|
* ks_pcie_v3_65_scan_bus() - keystone scan_bus post initialization
|
2018-10-17 14:40:59 +07:00
|
|
|
*
|
|
|
|
* This sets BAR0 to enable inbound access for MSI_IRQ register
|
|
|
|
*/
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_v3_65_scan_bus(struct pcie_port *pp)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
|
|
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
|
|
|
|
|
|
|
|
/* Configure and set up BAR0 */
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_set_dbi_mode(ks_pcie);
|
2018-10-17 14:40:59 +07:00
|
|
|
|
|
|
|
/* Enable BAR0 */
|
|
|
|
dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 1);
|
|
|
|
dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, SZ_4K - 1);
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_clear_dbi_mode(ks_pcie);
|
2018-10-17 14:40:59 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For BAR0, just setting bus address for inbound writes (MSI) should
|
|
|
|
* be sufficient. Use physical address to avoid any conflicts.
|
|
|
|
*/
|
|
|
|
dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, ks_pcie->app.start);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-17 14:41:01 +07:00
|
|
|
* ks_pcie_link_up() - Check if link up
|
2018-10-17 14:40:59 +07:00
|
|
|
*/
|
2018-10-17 14:41:01 +07:00
|
|
|
static int ks_pcie_link_up(struct dw_pcie *pci)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = dw_pcie_readl_dbi(pci, DEBUG0);
|
|
|
|
return (val & LTSSM_STATE_MASK) == LTSSM_STATE_L0;
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_initiate_link_train(struct keystone_pcie *ks_pcie)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
/* Disable Link training */
|
2018-10-17 14:41:01 +07:00
|
|
|
val = ks_pcie_app_readl(ks_pcie, CMD_STATUS);
|
2018-10-17 14:40:59 +07:00
|
|
|
val &= ~LTSSM_EN_VAL;
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_app_writel(ks_pcie, CMD_STATUS, LTSSM_EN_VAL | val);
|
2018-10-17 14:40:59 +07:00
|
|
|
|
|
|
|
/* Initiate Link Training */
|
2018-10-17 14:41:01 +07:00
|
|
|
val = ks_pcie_app_readl(ks_pcie, CMD_STATUS);
|
|
|
|
ks_pcie_app_writel(ks_pcie, CMD_STATUS, LTSSM_EN_VAL | val);
|
2018-10-17 14:40:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-17 14:41:01 +07:00
|
|
|
* ks_pcie_dw_host_init() - initialize host for v3_65 dw hardware
|
2018-10-17 14:40:59 +07:00
|
|
|
*
|
|
|
|
* Ioremap the register resources, initialize legacy irq domain
|
|
|
|
* and call dw_pcie_v3_65_host_init() API to initialize the Keystone
|
|
|
|
* PCI host controller.
|
|
|
|
*/
|
2018-10-17 14:41:01 +07:00
|
|
|
static int __init ks_pcie_dw_host_init(struct keystone_pcie *ks_pcie)
|
2018-10-17 14:40:59 +07:00
|
|
|
{
|
|
|
|
struct dw_pcie *pci = ks_pcie->pci;
|
|
|
|
struct pcie_port *pp = &pci->pp;
|
|
|
|
struct device *dev = pci->dev;
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
/* Index 0 is the config reg. space address */
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
pci->dbi_base = devm_pci_remap_cfg_resource(dev, res);
|
|
|
|
if (IS_ERR(pci->dbi_base))
|
|
|
|
return PTR_ERR(pci->dbi_base);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We set these same and is used in pcie rd/wr_other_conf
|
|
|
|
* functions
|
|
|
|
*/
|
|
|
|
pp->va_cfg0_base = pci->dbi_base + SPACE0_REMOTE_CFG_OFFSET;
|
|
|
|
pp->va_cfg1_base = pp->va_cfg0_base;
|
|
|
|
|
|
|
|
/* Index 1 is the application reg. space address */
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
|
|
|
|
ks_pcie->va_app_base = devm_ioremap_resource(dev, res);
|
|
|
|
if (IS_ERR(ks_pcie->va_app_base))
|
|
|
|
return PTR_ERR(ks_pcie->va_app_base);
|
|
|
|
|
|
|
|
ks_pcie->app = *res;
|
|
|
|
|
|
|
|
/* Create legacy IRQ domain */
|
|
|
|
ks_pcie->legacy_irq_domain =
|
|
|
|
irq_domain_add_linear(ks_pcie->legacy_intc_np,
|
|
|
|
PCI_NUM_INTX,
|
2018-10-17 14:41:01 +07:00
|
|
|
&ks_pcie_legacy_irq_domain_ops,
|
2018-10-17 14:40:59 +07:00
|
|
|
NULL);
|
|
|
|
if (!ks_pcie->legacy_irq_domain) {
|
|
|
|
dev_err(dev, "Failed to add irq domain for legacy irqs\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dw_pcie_host_init(pp);
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static void ks_pcie_quirk(struct pci_dev *dev)
|
2014-09-09 00:03:34 +07:00
|
|
|
{
|
|
|
|
struct pci_bus *bus = dev->bus;
|
2018-10-17 14:40:55 +07:00
|
|
|
struct pci_dev *bridge;
|
2014-09-09 00:03:34 +07:00
|
|
|
static const struct pci_device_id rc_pci_devids[] = {
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_TI, PCIE_RC_K2HK),
|
|
|
|
.class = PCI_CLASS_BRIDGE_PCI << 8, .class_mask = ~0, },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_TI, PCIE_RC_K2E),
|
|
|
|
.class = PCI_CLASS_BRIDGE_PCI << 8, .class_mask = ~0, },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_TI, PCIE_RC_K2L),
|
|
|
|
.class = PCI_CLASS_BRIDGE_PCI << 8, .class_mask = ~0, },
|
2018-10-17 14:40:54 +07:00
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_TI, PCIE_RC_K2G),
|
|
|
|
.class = PCI_CLASS_BRIDGE_PCI << 8, .class_mask = ~0, },
|
2014-09-09 00:03:34 +07:00
|
|
|
{ 0, },
|
|
|
|
};
|
|
|
|
|
|
|
|
if (pci_is_root_bus(bus))
|
2018-10-17 14:40:55 +07:00
|
|
|
bridge = dev;
|
2014-09-09 00:03:34 +07:00
|
|
|
|
|
|
|
/* look for the host bridge */
|
|
|
|
while (!pci_is_root_bus(bus)) {
|
|
|
|
bridge = bus->self;
|
|
|
|
bus = bus->parent;
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:40:55 +07:00
|
|
|
if (!bridge)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keystone PCI controller has a h/w limitation of
|
|
|
|
* 256 bytes maximum read request size. It can't handle
|
|
|
|
* anything higher than this. So force this limit on
|
|
|
|
* all downstream devices.
|
|
|
|
*/
|
|
|
|
if (pci_match_id(rc_pci_devids, bridge)) {
|
|
|
|
if (pcie_get_readrq(dev) > 256) {
|
|
|
|
dev_info(&dev->dev, "limiting MRRS to 256\n");
|
|
|
|
pcie_set_readrq(dev, 256);
|
2014-09-09 00:03:34 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-17 14:41:01 +07:00
|
|
|
DECLARE_PCI_FIXUP_ENABLE(PCI_ANY_ID, PCI_ANY_ID, ks_pcie_quirk);
|
2014-09-09 00:03:34 +07:00
|
|
|
|
2014-09-03 06:26:19 +07:00
|
|
|
static int ks_pcie_establish_link(struct keystone_pcie *ks_pcie)
|
|
|
|
{
|
2017-02-15 20:18:14 +07:00
|
|
|
struct dw_pcie *pci = ks_pcie->pci;
|
|
|
|
struct device *dev = pci->dev;
|
2014-09-03 06:26:19 +07:00
|
|
|
|
2017-02-15 20:18:14 +07:00
|
|
|
if (dw_pcie_link_up(pci)) {
|
2018-05-09 23:57:36 +07:00
|
|
|
dev_info(dev, "Link already up\n");
|
2014-09-03 06:26:19 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_initiate_link_train(ks_pcie);
|
2018-10-17 14:40:57 +07:00
|
|
|
|
2014-09-03 06:26:19 +07:00
|
|
|
/* check if the link is up or not */
|
2018-10-17 14:40:57 +07:00
|
|
|
if (!dw_pcie_wait_for_link(pci))
|
|
|
|
return 0;
|
2014-09-03 06:26:19 +07:00
|
|
|
|
2016-10-12 10:48:42 +07:00
|
|
|
dev_err(dev, "phy link never came up\n");
|
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-11 03:44:35 +07:00
|
|
|
return -ETIMEDOUT;
|
2014-09-03 06:26:19 +07:00
|
|
|
}
|
|
|
|
|
2015-09-14 15:42:37 +07:00
|
|
|
static void ks_pcie_msi_irq_handler(struct irq_desc *desc)
|
2014-09-03 06:26:19 +07:00
|
|
|
{
|
2015-07-17 04:24:10 +07:00
|
|
|
unsigned int irq = irq_desc_get_irq(desc);
|
2014-09-03 06:26:19 +07:00
|
|
|
struct keystone_pcie *ks_pcie = irq_desc_get_handler_data(desc);
|
|
|
|
u32 offset = irq - ks_pcie->msi_host_irqs[0];
|
2017-02-15 20:18:14 +07:00
|
|
|
struct dw_pcie *pci = ks_pcie->pci;
|
|
|
|
struct device *dev = pci->dev;
|
2014-09-03 06:26:19 +07:00
|
|
|
struct irq_chip *chip = irq_desc_get_chip(desc);
|
|
|
|
|
2016-10-12 10:48:42 +07:00
|
|
|
dev_dbg(dev, "%s, irq %d\n", __func__, irq);
|
2014-09-03 06:26:19 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The chained irq handler installation would have replaced normal
|
|
|
|
* interrupt driver handler so we need to take care of mask/unmask and
|
|
|
|
* ack operation.
|
|
|
|
*/
|
|
|
|
chained_irq_enter(chip, desc);
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_handle_msi_irq(ks_pcie, offset);
|
2014-09-03 06:26:19 +07:00
|
|
|
chained_irq_exit(chip, desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ks_pcie_legacy_irq_handler() - Handle legacy interrupt
|
|
|
|
* @irq: IRQ line for legacy interrupts
|
|
|
|
* @desc: Pointer to irq descriptor
|
|
|
|
*
|
|
|
|
* Traverse through pending legacy interrupts and invoke handler for each. Also
|
|
|
|
* takes care of interrupt controller level mask/ack operation.
|
|
|
|
*/
|
2015-09-14 15:42:37 +07:00
|
|
|
static void ks_pcie_legacy_irq_handler(struct irq_desc *desc)
|
2014-09-03 06:26:19 +07:00
|
|
|
{
|
2015-07-17 04:24:10 +07:00
|
|
|
unsigned int irq = irq_desc_get_irq(desc);
|
2014-09-03 06:26:19 +07:00
|
|
|
struct keystone_pcie *ks_pcie = irq_desc_get_handler_data(desc);
|
2017-02-15 20:18:14 +07:00
|
|
|
struct dw_pcie *pci = ks_pcie->pci;
|
|
|
|
struct device *dev = pci->dev;
|
2014-09-03 06:26:19 +07:00
|
|
|
u32 irq_offset = irq - ks_pcie->legacy_host_irqs[0];
|
|
|
|
struct irq_chip *chip = irq_desc_get_chip(desc);
|
|
|
|
|
2016-10-12 10:48:42 +07:00
|
|
|
dev_dbg(dev, ": Handling legacy irq %d\n", irq);
|
2014-09-03 06:26:19 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The chained irq handler installation would have replaced normal
|
|
|
|
* interrupt driver handler so we need to take care of mask/unmask and
|
|
|
|
* ack operation.
|
|
|
|
*/
|
|
|
|
chained_irq_enter(chip, desc);
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_handle_legacy_irq(ks_pcie, irq_offset);
|
2014-09-03 06:26:19 +07:00
|
|
|
chained_irq_exit(chip, desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ks_pcie_get_irq_controller_info(struct keystone_pcie *ks_pcie,
|
|
|
|
char *controller, int *num_irqs)
|
|
|
|
{
|
2016-04-11 21:50:31 +07:00
|
|
|
int temp, max_host_irqs, legacy = 1, *host_irqs;
|
2017-02-15 20:18:14 +07:00
|
|
|
struct device *dev = ks_pcie->pci->dev;
|
2014-09-03 06:26:19 +07:00
|
|
|
struct device_node *np_pcie = dev->of_node, **np_temp;
|
|
|
|
|
|
|
|
if (!strcmp(controller, "msi-interrupt-controller"))
|
|
|
|
legacy = 0;
|
|
|
|
|
|
|
|
if (legacy) {
|
|
|
|
np_temp = &ks_pcie->legacy_intc_np;
|
2017-08-16 04:27:57 +07:00
|
|
|
max_host_irqs = PCI_NUM_INTX;
|
2014-09-03 06:26:19 +07:00
|
|
|
host_irqs = &ks_pcie->legacy_host_irqs[0];
|
|
|
|
} else {
|
|
|
|
np_temp = &ks_pcie->msi_intc_np;
|
|
|
|
max_host_irqs = MAX_MSI_HOST_IRQS;
|
|
|
|
host_irqs = &ks_pcie->msi_host_irqs[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* interrupt controller is in a child node */
|
2017-11-17 20:38:31 +07:00
|
|
|
*np_temp = of_get_child_by_name(np_pcie, controller);
|
2014-09-03 06:26:19 +07:00
|
|
|
if (!(*np_temp)) {
|
|
|
|
dev_err(dev, "Node for %s is absent\n", controller);
|
2016-04-11 21:50:31 +07:00
|
|
|
return -EINVAL;
|
2014-09-03 06:26:19 +07:00
|
|
|
}
|
2016-04-11 21:50:31 +07:00
|
|
|
|
2014-09-03 06:26:19 +07:00
|
|
|
temp = of_irq_count(*np_temp);
|
2016-04-11 21:50:31 +07:00
|
|
|
if (!temp) {
|
|
|
|
dev_err(dev, "No IRQ entries in %s\n", controller);
|
2017-11-17 20:38:31 +07:00
|
|
|
of_node_put(*np_temp);
|
2016-04-11 21:50:31 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-09-03 06:26:19 +07:00
|
|
|
if (temp > max_host_irqs)
|
|
|
|
dev_warn(dev, "Too many %s interrupts defined %u\n",
|
|
|
|
(legacy ? "legacy" : "MSI"), temp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* support upto max_host_irqs. In dt from index 0 to 3 (legacy) or 0 to
|
|
|
|
* 7 (MSI)
|
|
|
|
*/
|
|
|
|
for (temp = 0; temp < max_host_irqs; temp++) {
|
|
|
|
host_irqs[temp] = irq_of_parse_and_map(*np_temp, temp);
|
2014-11-15 05:19:03 +07:00
|
|
|
if (!host_irqs[temp])
|
2014-09-03 06:26:19 +07:00
|
|
|
break;
|
|
|
|
}
|
2016-04-11 21:50:31 +07:00
|
|
|
|
2017-11-17 20:38:31 +07:00
|
|
|
of_node_put(*np_temp);
|
|
|
|
|
2014-09-03 06:26:19 +07:00
|
|
|
if (temp) {
|
|
|
|
*num_irqs = temp;
|
2016-04-11 21:50:31 +07:00
|
|
|
return 0;
|
2014-09-03 06:26:19 +07:00
|
|
|
}
|
2016-04-11 21:50:31 +07:00
|
|
|
|
|
|
|
return -EINVAL;
|
2014-09-03 06:26:19 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ks_pcie_setup_interrupts(struct keystone_pcie *ks_pcie)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Legacy IRQ */
|
|
|
|
for (i = 0; i < ks_pcie->num_legacy_host_irqs; i++) {
|
2015-06-22 02:11:05 +07:00
|
|
|
irq_set_chained_handler_and_data(ks_pcie->legacy_host_irqs[i],
|
|
|
|
ks_pcie_legacy_irq_handler,
|
|
|
|
ks_pcie);
|
2014-09-03 06:26:19 +07:00
|
|
|
}
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_enable_legacy_irqs(ks_pcie);
|
2014-09-03 06:26:19 +07:00
|
|
|
|
|
|
|
/* MSI IRQ */
|
|
|
|
if (IS_ENABLED(CONFIG_PCI_MSI)) {
|
|
|
|
for (i = 0; i < ks_pcie->num_msi_host_irqs; i++) {
|
PCI/keystone: Fix race in installing chained IRQ handler
Fix a race where a pending interrupt could be received and the handler
called before the handler's data has been setup, by converting to
irq_set_chained_handler_and_data().
Search and conversion was done with coccinelle:
@@
expression E1, E2, E3;
@@
(
-if (irq_set_chained_handler(E1, E3) != 0)
- BUG();
|
-irq_set_chained_handler(E1, E3);
)
-irq_set_handler_data(E1, E2);
+irq_set_chained_handler_and_data(E1, E3, E2);
@@
expression E1, E2, E3;
@@
(
-if (irq_set_chained_handler(E1, E3) != 0)
- BUG();
...
|
-irq_set_chained_handler(E1, E3);
...
)
-irq_set_handler_data(E1, E2);
+irq_set_chained_handler_and_data(E1, E3, E2);
Reported-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: Murali Karicheri <m-karicheri2@ti.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
2015-06-22 01:16:09 +07:00
|
|
|
irq_set_chained_handler_and_data(ks_pcie->msi_host_irqs[i],
|
|
|
|
ks_pcie_msi_irq_handler,
|
|
|
|
ks_pcie);
|
2014-09-03 06:26:19 +07:00
|
|
|
}
|
|
|
|
}
|
2016-04-11 21:50:30 +07:00
|
|
|
|
|
|
|
if (ks_pcie->error_irq > 0)
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_enable_error_irq(ks_pcie);
|
2014-09-03 06:26:19 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When a PCI device does not exist during config cycles, keystone host gets a
|
|
|
|
* bus error instead of returning 0xffffffff. This handler always returns 0
|
|
|
|
* for this kind of faults.
|
|
|
|
*/
|
2018-10-17 14:41:01 +07:00
|
|
|
static int ks_pcie_fault(unsigned long addr, unsigned int fsr,
|
|
|
|
struct pt_regs *regs)
|
2014-09-03 06:26:19 +07:00
|
|
|
{
|
|
|
|
unsigned long instr = *(unsigned long *) instruction_pointer(regs);
|
|
|
|
|
|
|
|
if ((instr & 0x0e100090) == 0x00100090) {
|
|
|
|
int reg = (instr >> 12) & 15;
|
|
|
|
|
|
|
|
regs->uregs[reg] = -1;
|
|
|
|
regs->ARM_pc += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-16 13:39:45 +07:00
|
|
|
static int __init ks_pcie_host_init(struct pcie_port *pp)
|
2014-09-03 06:26:19 +07:00
|
|
|
{
|
2017-02-15 20:18:14 +07:00
|
|
|
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
|
|
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
|
2014-09-03 06:26:19 +07:00
|
|
|
|
2018-10-17 14:40:56 +07:00
|
|
|
dw_pcie_setup_rc(pp);
|
|
|
|
|
2014-09-03 06:26:19 +07:00
|
|
|
ks_pcie_establish_link(ks_pcie);
|
2018-10-17 14:41:01 +07:00
|
|
|
ks_pcie_setup_rc_app_regs(ks_pcie);
|
2014-09-03 06:26:19 +07:00
|
|
|
ks_pcie_setup_interrupts(ks_pcie);
|
|
|
|
writew(PCI_IO_RANGE_TYPE_32 | (PCI_IO_RANGE_TYPE_32 << 8),
|
2017-02-15 20:18:14 +07:00
|
|
|
pci->dbi_base + PCI_IO_BASE);
|
2014-09-03 06:26:19 +07:00
|
|
|
|
|
|
|
/* update the Vendor ID */
|
2017-02-15 20:18:14 +07:00
|
|
|
writew(ks_pcie->device_id, pci->dbi_base + PCI_DEVICE_ID);
|
2014-09-03 06:26:19 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PCIe access errors that result into OCP errors are caught by ARM as
|
|
|
|
* "External aborts"
|
|
|
|
*/
|
2018-10-17 14:41:01 +07:00
|
|
|
hook_fault_code(17, ks_pcie_fault, SIGBUS, 0,
|
2014-09-03 06:26:19 +07:00
|
|
|
"Asynchronous external abort");
|
2017-07-16 13:39:45 +07:00
|
|
|
|
|
|
|
return 0;
|
2014-09-03 06:26:19 +07:00
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static const struct dw_pcie_host_ops ks_pcie_host_ops = {
|
|
|
|
.rd_other_conf = ks_pcie_rd_other_conf,
|
|
|
|
.wr_other_conf = ks_pcie_wr_other_conf,
|
2014-09-03 06:26:19 +07:00
|
|
|
.host_init = ks_pcie_host_init,
|
2018-10-17 14:41:01 +07:00
|
|
|
.msi_set_irq = ks_pcie_msi_set_irq,
|
|
|
|
.msi_clear_irq = ks_pcie_msi_clear_irq,
|
|
|
|
.get_msi_addr = ks_pcie_get_msi_addr,
|
|
|
|
.msi_host_init = ks_pcie_msi_host_init,
|
|
|
|
.msi_irq_ack = ks_pcie_msi_irq_ack,
|
|
|
|
.scan_bus = ks_pcie_v3_65_scan_bus,
|
2014-09-03 06:26:19 +07:00
|
|
|
};
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static irqreturn_t ks_pcie_err_irq_handler(int irq, void *priv)
|
2016-04-11 21:50:30 +07:00
|
|
|
{
|
|
|
|
struct keystone_pcie *ks_pcie = priv;
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
return ks_pcie_handle_error_irq(ks_pcie);
|
2016-04-11 21:50:30 +07:00
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static int __init ks_pcie_add_pcie_port(struct keystone_pcie *ks_pcie,
|
|
|
|
struct platform_device *pdev)
|
2014-09-03 06:26:19 +07:00
|
|
|
{
|
2017-02-15 20:18:14 +07:00
|
|
|
struct dw_pcie *pci = ks_pcie->pci;
|
|
|
|
struct pcie_port *pp = &pci->pp;
|
|
|
|
struct device *dev = &pdev->dev;
|
2014-09-03 06:26:19 +07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ks_pcie_get_irq_controller_info(ks_pcie,
|
|
|
|
"legacy-interrupt-controller",
|
|
|
|
&ks_pcie->num_legacy_host_irqs);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_PCI_MSI)) {
|
|
|
|
ret = ks_pcie_get_irq_controller_info(ks_pcie,
|
|
|
|
"msi-interrupt-controller",
|
|
|
|
&ks_pcie->num_msi_host_irqs);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-04-11 21:50:30 +07:00
|
|
|
/*
|
|
|
|
* Index 0 is the platform interrupt for error interrupt
|
|
|
|
* from RC. This is optional.
|
|
|
|
*/
|
|
|
|
ks_pcie->error_irq = irq_of_parse_and_map(ks_pcie->np, 0);
|
|
|
|
if (ks_pcie->error_irq <= 0)
|
2016-10-12 10:48:42 +07:00
|
|
|
dev_info(dev, "no error IRQ defined\n");
|
2016-04-11 21:50:30 +07:00
|
|
|
else {
|
2018-10-17 14:41:01 +07:00
|
|
|
ret = request_irq(ks_pcie->error_irq, ks_pcie_err_irq_handler,
|
2016-07-28 23:16:18 +07:00
|
|
|
IRQF_SHARED, "pcie-error-irq", ks_pcie);
|
|
|
|
if (ret < 0) {
|
2016-10-12 10:48:42 +07:00
|
|
|
dev_err(dev, "failed to request error IRQ %d\n",
|
2016-04-11 21:50:30 +07:00
|
|
|
ks_pcie->error_irq);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
pp->ops = &ks_pcie_host_ops;
|
|
|
|
ret = ks_pcie_dw_host_init(ks_pcie);
|
2014-09-03 06:26:19 +07:00
|
|
|
if (ret) {
|
2016-10-12 10:48:42 +07:00
|
|
|
dev_err(dev, "failed to initialize host\n");
|
2014-09-03 06:26:19 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-04-11 21:50:31 +07:00
|
|
|
return 0;
|
2014-09-03 06:26:19 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id ks_pcie_of_match[] = {
|
|
|
|
{
|
|
|
|
.type = "pci",
|
|
|
|
.compatible = "ti,keystone-pcie",
|
|
|
|
},
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
static const struct dw_pcie_ops ks_pcie_dw_pcie_ops = {
|
|
|
|
.link_up = ks_pcie_link_up,
|
2017-02-15 20:18:14 +07:00
|
|
|
};
|
|
|
|
|
2014-09-03 06:26:19 +07:00
|
|
|
static int __exit ks_pcie_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct keystone_pcie *ks_pcie = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
clk_disable_unprepare(ks_pcie->clk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init ks_pcie_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
2017-02-15 20:18:14 +07:00
|
|
|
struct dw_pcie *pci;
|
2014-09-03 06:26:19 +07:00
|
|
|
struct keystone_pcie *ks_pcie;
|
|
|
|
struct resource *res;
|
|
|
|
void __iomem *reg_p;
|
|
|
|
struct phy *phy;
|
2016-04-11 21:50:31 +07:00
|
|
|
int ret;
|
2014-09-03 06:26:19 +07:00
|
|
|
|
2016-10-12 10:48:42 +07:00
|
|
|
ks_pcie = devm_kzalloc(dev, sizeof(*ks_pcie), GFP_KERNEL);
|
2014-11-12 10:22:56 +07:00
|
|
|
if (!ks_pcie)
|
2014-09-03 06:26:19 +07:00
|
|
|
return -ENOMEM;
|
2014-11-12 10:22:56 +07:00
|
|
|
|
2017-02-15 20:18:14 +07:00
|
|
|
pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
|
|
|
|
if (!pci)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pci->dev = dev;
|
2018-10-17 14:41:01 +07:00
|
|
|
pci->ops = &ks_pcie_dw_pcie_ops;
|
2014-09-03 06:26:19 +07:00
|
|
|
|
2017-02-25 17:08:12 +07:00
|
|
|
ks_pcie->pci = pci;
|
|
|
|
|
2014-09-03 06:26:19 +07:00
|
|
|
/* initialize SerDes Phy if present */
|
|
|
|
phy = devm_phy_get(dev, "pcie-phy");
|
2016-03-07 11:32:21 +07:00
|
|
|
if (PTR_ERR_OR_ZERO(phy) == -EPROBE_DEFER)
|
|
|
|
return PTR_ERR(phy);
|
|
|
|
|
2014-09-03 06:26:19 +07:00
|
|
|
if (!IS_ERR_OR_NULL(phy)) {
|
|
|
|
ret = phy_init(phy);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-09-11 00:12:38 +07:00
|
|
|
/* index 2 is to read PCI DEVICE_ID */
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
|
2014-09-03 06:26:19 +07:00
|
|
|
reg_p = devm_ioremap_resource(dev, res);
|
|
|
|
if (IS_ERR(reg_p))
|
|
|
|
return PTR_ERR(reg_p);
|
2014-09-11 00:12:39 +07:00
|
|
|
ks_pcie->device_id = readl(reg_p) >> 16;
|
|
|
|
devm_iounmap(dev, reg_p);
|
|
|
|
devm_release_mem_region(dev, res->start, resource_size(res));
|
2014-09-03 06:26:19 +07:00
|
|
|
|
2016-04-11 21:50:30 +07:00
|
|
|
ks_pcie->np = dev->of_node;
|
2014-09-03 06:26:19 +07:00
|
|
|
platform_set_drvdata(pdev, ks_pcie);
|
|
|
|
ks_pcie->clk = devm_clk_get(dev, "pcie");
|
|
|
|
if (IS_ERR(ks_pcie->clk)) {
|
|
|
|
dev_err(dev, "Failed to get pcie rc clock\n");
|
|
|
|
return PTR_ERR(ks_pcie->clk);
|
|
|
|
}
|
|
|
|
ret = clk_prepare_enable(ks_pcie->clk);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-10-17 14:41:01 +07:00
|
|
|
ret = ks_pcie_add_pcie_port(ks_pcie, pdev);
|
2014-09-03 06:26:19 +07:00
|
|
|
if (ret < 0)
|
|
|
|
goto fail_clk;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
fail_clk:
|
|
|
|
clk_disable_unprepare(ks_pcie->clk);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver ks_pcie_driver __refdata = {
|
|
|
|
.probe = ks_pcie_probe,
|
|
|
|
.remove = __exit_p(ks_pcie_remove),
|
|
|
|
.driver = {
|
|
|
|
.name = "keystone-pcie",
|
|
|
|
.of_match_table = of_match_ptr(ks_pcie_of_match),
|
|
|
|
},
|
|
|
|
};
|
2016-07-03 06:13:26 +07:00
|
|
|
builtin_platform_driver(ks_pcie_driver);
|