Changes in 4.9.214 media: iguanair: fix endpoint sanity check x86/cpu: Update cached HLE state on write to TSX_CTRL_CPUID_CLEAR sparc32: fix struct ipc64_perm type definition ASoC: qcom: Fix of-node refcount unbalance to link->codec_of_node cls_rsvp: fix rsvp_policy gtp: use __GFP_NOWARN to avoid memalloc warning net: hsr: fix possible NULL deref in hsr_handle_frame() net_sched: fix an OOB access in cls_tcindex rxrpc: Fix insufficient receive notification generation rxrpc: Fix NULL pointer deref due to call->conn being cleared on disconnect tcp: clear tp->total_retrans in tcp_disconnect() tcp: clear tp->delivered in tcp_disconnect() tcp: clear tp->data_segs{in|out} in tcp_disconnect() tcp: clear tp->segs_{in|out} in tcp_disconnect() media: uvcvideo: Avoid cyclic entity chains due to malformed USB descriptors mfd: dln2: More sanity checking for endpoints brcmfmac: Fix memory leak in brcmf_usbdev_qinit usb: gadget: legacy: set max_speed to super-speed usb: gadget: f_ncm: Use atomic_t to track in-flight request usb: gadget: f_ecm: Use atomic_t to track in-flight request ALSA: dummy: Fix PCM format loop in proc output media/v4l2-core: set pages dirty upon releasing DMA buffers media: v4l2-rect.h: fix v4l2_rect_map_inside() top/left adjustments lib/test_kasan.c: fix memory leak in kmalloc_oob_krealloc_more() powerpc/pseries: Advance pfn if section is not present in lmb_is_removable() mmc: spi: Toggle SPI polarity, do not hardcode it PCI: keystone: Fix link training retries initiation ubifs: Change gfp flags in page allocation for bulk read ubifs: Fix deadlock in concurrent bulk-read and writepage crypto: api - Check spawn->alg under lock in crypto_drop_spawn scsi: qla2xxx: Fix mtcp dump collection failure power: supply: ltc2941-battery-gauge: fix use-after-free of: Add OF_DMA_DEFAULT_COHERENT & select it on powerpc dm space map common: fix to ensure new block isn't already in use crypto: pcrypt - Do not clear MAY_SLEEP flag in original request crypto: atmel-aes - Fix counter overflow in CTR mode crypto: api - Fix race condition in crypto_spawn_alg crypto: picoxcell - adjust the position of tasklet_init and fix missed tasklet_kill btrfs: set trans->drity in btrfs_commit_transaction ARM: tegra: Enable PLLP bypass during Tegra124 LP1 mwifiex: fix unbalanced locking in mwifiex_process_country_ie() sunrpc: expiry_time should be seconds not timeval KVM: x86: Refactor prefix decoding to prevent Spectre-v1/L1TF attacks KVM: x86: Protect DR-based index computations from Spectre-v1/L1TF attacks KVM: x86: Protect kvm_lapic_reg_write() from Spectre-v1/L1TF attacks KVM: x86: Protect kvm_hv_msr_[get|set]_crash_data() from Spectre-v1/L1TF attacks KVM: x86: Protect ioapic_write_indirect() from Spectre-v1/L1TF attacks KVM: x86: Protect MSR-based index computations in pmu.h from Spectre-v1/L1TF attacks KVM: x86: Protect ioapic_read_indirect() from Spectre-v1/L1TF attacks KVM: x86: Protect MSR-based index computations from Spectre-v1/L1TF attacks in x86.c KVM: x86: Protect x86_decode_insn from Spectre-v1/L1TF attacks KVM: x86: Protect MSR-based index computations in fixed_msr_to_seg_unit() from Spectre-v1/L1TF attacks KVM: PPC: Book3S HV: Uninit vCPU if vcore creation fails KVM: PPC: Book3S PR: Free shared page if mmu initialization fails KVM: x86: Free wbinvd_dirty_mask if vCPU creation fails clk: tegra: Mark fuse clock as critical scsi: qla2xxx: Fix the endianness of the qla82xx_get_fw_size() return type scsi: csiostor: Adjust indentation in csio_device_reset scsi: qla4xxx: Adjust indentation in qla4xxx_mem_free ext2: Adjust indentation in ext2_fill_super powerpc/44x: Adjust indentation in ibm4xx_denali_fixup_memsize NFC: pn544: Adjust indentation in pn544_hci_check_presence ppp: Adjust indentation into ppp_async_input net: smc911x: Adjust indentation in smc911x_phy_configure net: tulip: Adjust indentation in {dmfe, uli526x}_init_module IB/mlx5: Fix outstanding_pi index for GSI qps nfsd: fix delay timer on 32-bit architectures nfsd: fix jiffies/time_t mixup in LRU list ubi: fastmap: Fix inverted logic in seen selfcheck ubi: Fix an error pointer dereference in error handling code mfd: da9062: Fix watchdog compatible string mfd: rn5t618: Mark ADC control register volatile net: systemport: Avoid RBUF stuck in Wake-on-LAN mode bonding/alb: properly access headers in bond_alb_xmit() NFS: switch back to to ->iterate() NFS: Fix memory leaks and corruption in readdir NFS: Fix bool initialization/comparison NFS: Directory page cache pages need to be locked when read ext4: fix deadlock allocating crypto bounce page from mempool Btrfs: fix assertion failure on fsync with NO_HOLES enabled btrfs: use bool argument in free_root_pointers() btrfs: remove trivial locking wrappers of tree mod log Btrfs: fix race between adding and putting tree mod seq elements and nodes drm: atmel-hlcdc: enable clock before configuring timing engine KVM: x86: Protect pmu_intel.c from Spectre-v1/L1TF attacks btrfs: flush write bio if we loop in extent_write_cache_pages KVM: x86/mmu: Apply max PA check for MMIO sptes to 32-bit KVM KVM: VMX: Add non-canonical check on writes to RTIT address MSRs KVM: nVMX: vmread should not set rflags to specify success in case of #PF cifs: fail i/o on soft mounts if sessionsetup errors out clocksource: Prevent double add_timer_on() for watchdog_timer perf/core: Fix mlock accounting in perf_mmap() rxrpc: Fix service call disconnection ASoC: pcm: update FE/BE trigger order based on the command RDMA/netlink: Do not always generate an ACK for some netlink operations scsi: ufs: Fix ufshcd_probe_hba() reture value in case ufshcd_scsi_add_wlus() fails PCI: Don't disable bridge BARs when assigning bus resources nfs: NFS_SWAP should depend on SWAP NFSv4: try lease recovery on NFS4ERR_EXPIRED rtc: hym8563: Return -EINVAL if the time is known to be invalid rtc: cmos: Stop using shared IRQ ARC: [plat-axs10x]: Add missing multicast filter number to GMAC node ARM: dts: at91: sama5d3: fix maximum peripheral clock rates ARM: dts: at91: sama5d3: define clock rate range for tcb1 tools/power/acpi: fix compilation error powerpc/pseries: Allow not having ibm, hypertas-functions::hcall-multi-tce for DDW pinctrl: sh-pfc: r8a7778: Fix duplicate SDSELF_B and SD1_CLK_B scsi: megaraid_sas: Do not initiate OCR if controller is not in ready state dm: fix potential for q->make_request_fn NULL pointer mwifiex: Fix possible buffer overflows in mwifiex_ret_wmm_get_status() mwifiex: Fix possible buffer overflows in mwifiex_cmd_append_vsie_tlv() libertas: don't exit from lbs_ibss_join_existing() with RCU read lock held libertas: make lbs_ibss_join_existing() return error code on rates overflow Linux 4.9.214 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ieac421e286126a690fd2c206ea7b4dde45e4a475
561 lines
15 KiB
C
561 lines
15 KiB
C
/*
|
|
* Designware application register space functions for Keystone PCI controller
|
|
*
|
|
* Copyright (C) 2013-2014 Texas Instruments., Ltd.
|
|
* http://www.ti.com
|
|
*
|
|
* Author: Murali Karicheri <m-karicheri2@ti.com>
|
|
*
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/irq.h>
|
|
#include <linux/irqdomain.h>
|
|
#include <linux/irqreturn.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_pci.h>
|
|
#include <linux/pci.h>
|
|
#include <linux/platform_device.h>
|
|
|
|
#include "pcie-designware.h"
|
|
#include "pci-keystone.h"
|
|
|
|
/* Application register defines */
|
|
#define LTSSM_EN_VAL 1
|
|
#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 to_keystone_pcie(x) container_of(x, struct keystone_pcie, pp)
|
|
|
|
static inline void update_reg_offset_bit_pos(u32 offset, u32 *reg_offset,
|
|
u32 *bit_pos)
|
|
{
|
|
*reg_offset = offset % 8;
|
|
*bit_pos = offset >> 3;
|
|
}
|
|
|
|
phys_addr_t ks_dw_pcie_get_msi_addr(struct pcie_port *pp)
|
|
{
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
|
|
|
|
return ks_pcie->app.start + MSI_IRQ;
|
|
}
|
|
|
|
static u32 ks_dw_app_readl(struct keystone_pcie *ks_pcie, u32 offset)
|
|
{
|
|
return readl(ks_pcie->va_app_base + offset);
|
|
}
|
|
|
|
static void ks_dw_app_writel(struct keystone_pcie *ks_pcie, u32 offset, u32 val)
|
|
{
|
|
writel(val, ks_pcie->va_app_base + offset);
|
|
}
|
|
|
|
void ks_dw_pcie_handle_msi_irq(struct keystone_pcie *ks_pcie, int offset)
|
|
{
|
|
struct pcie_port *pp = &ks_pcie->pp;
|
|
struct device *dev = pp->dev;
|
|
u32 pending, vector;
|
|
int src, virq;
|
|
|
|
pending = ks_dw_app_readl(ks_pcie, MSI0_IRQ_STATUS + (offset << 4));
|
|
|
|
/*
|
|
* 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);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void ks_dw_pcie_msi_irq_ack(struct irq_data *d)
|
|
{
|
|
u32 offset, reg_offset, bit_pos;
|
|
struct keystone_pcie *ks_pcie;
|
|
struct msi_desc *msi;
|
|
struct pcie_port *pp;
|
|
|
|
msi = irq_data_get_msi_desc(d);
|
|
pp = (struct pcie_port *) msi_desc_to_pci_sysdata(msi);
|
|
ks_pcie = to_keystone_pcie(pp);
|
|
offset = d->irq - irq_linear_revmap(pp->irq_domain, 0);
|
|
update_reg_offset_bit_pos(offset, ®_offset, &bit_pos);
|
|
|
|
ks_dw_app_writel(ks_pcie, MSI0_IRQ_STATUS + (reg_offset << 4),
|
|
BIT(bit_pos));
|
|
ks_dw_app_writel(ks_pcie, IRQ_EOI, reg_offset + MSI_IRQ_OFFSET);
|
|
}
|
|
|
|
void ks_dw_pcie_msi_set_irq(struct pcie_port *pp, int irq)
|
|
{
|
|
u32 reg_offset, bit_pos;
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
|
|
|
|
update_reg_offset_bit_pos(irq, ®_offset, &bit_pos);
|
|
ks_dw_app_writel(ks_pcie, MSI0_IRQ_ENABLE_SET + (reg_offset << 4),
|
|
BIT(bit_pos));
|
|
}
|
|
|
|
void ks_dw_pcie_msi_clear_irq(struct pcie_port *pp, int irq)
|
|
{
|
|
u32 reg_offset, bit_pos;
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
|
|
|
|
update_reg_offset_bit_pos(irq, ®_offset, &bit_pos);
|
|
ks_dw_app_writel(ks_pcie, MSI0_IRQ_ENABLE_CLR + (reg_offset << 4),
|
|
BIT(bit_pos));
|
|
}
|
|
|
|
static void ks_dw_pcie_msi_irq_mask(struct irq_data *d)
|
|
{
|
|
struct keystone_pcie *ks_pcie;
|
|
struct msi_desc *msi;
|
|
struct pcie_port *pp;
|
|
u32 offset;
|
|
|
|
msi = irq_data_get_msi_desc(d);
|
|
pp = (struct pcie_port *) msi_desc_to_pci_sysdata(msi);
|
|
ks_pcie = to_keystone_pcie(pp);
|
|
offset = d->irq - irq_linear_revmap(pp->irq_domain, 0);
|
|
|
|
/* Mask the end point if PVM implemented */
|
|
if (IS_ENABLED(CONFIG_PCI_MSI)) {
|
|
if (msi->msi_attrib.maskbit)
|
|
pci_msi_mask_irq(d);
|
|
}
|
|
|
|
ks_dw_pcie_msi_clear_irq(pp, offset);
|
|
}
|
|
|
|
static void ks_dw_pcie_msi_irq_unmask(struct irq_data *d)
|
|
{
|
|
struct keystone_pcie *ks_pcie;
|
|
struct msi_desc *msi;
|
|
struct pcie_port *pp;
|
|
u32 offset;
|
|
|
|
msi = irq_data_get_msi_desc(d);
|
|
pp = (struct pcie_port *) msi_desc_to_pci_sysdata(msi);
|
|
ks_pcie = to_keystone_pcie(pp);
|
|
offset = d->irq - irq_linear_revmap(pp->irq_domain, 0);
|
|
|
|
/* Mask the end point if PVM implemented */
|
|
if (IS_ENABLED(CONFIG_PCI_MSI)) {
|
|
if (msi->msi_attrib.maskbit)
|
|
pci_msi_unmask_irq(d);
|
|
}
|
|
|
|
ks_dw_pcie_msi_set_irq(pp, offset);
|
|
}
|
|
|
|
static struct irq_chip ks_dw_pcie_msi_irq_chip = {
|
|
.name = "Keystone-PCIe-MSI-IRQ",
|
|
.irq_ack = ks_dw_pcie_msi_irq_ack,
|
|
.irq_mask = ks_dw_pcie_msi_irq_mask,
|
|
.irq_unmask = ks_dw_pcie_msi_irq_unmask,
|
|
};
|
|
|
|
static int ks_dw_pcie_msi_map(struct irq_domain *domain, unsigned int irq,
|
|
irq_hw_number_t hwirq)
|
|
{
|
|
irq_set_chip_and_handler(irq, &ks_dw_pcie_msi_irq_chip,
|
|
handle_level_irq);
|
|
irq_set_chip_data(irq, domain->host_data);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct irq_domain_ops ks_dw_pcie_msi_domain_ops = {
|
|
.map = ks_dw_pcie_msi_map,
|
|
};
|
|
|
|
int ks_dw_pcie_msi_host_init(struct pcie_port *pp, struct msi_controller *chip)
|
|
{
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
|
|
struct device *dev = pp->dev;
|
|
int i;
|
|
|
|
pp->irq_domain = irq_domain_add_linear(ks_pcie->msi_intc_np,
|
|
MAX_MSI_IRQS,
|
|
&ks_dw_pcie_msi_domain_ops,
|
|
chip);
|
|
if (!pp->irq_domain) {
|
|
dev_err(dev, "irq domain init failed\n");
|
|
return -ENXIO;
|
|
}
|
|
|
|
for (i = 0; i < MAX_MSI_IRQS; i++)
|
|
irq_create_mapping(pp->irq_domain, i);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void ks_dw_pcie_enable_legacy_irqs(struct keystone_pcie *ks_pcie)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_LEGACY_IRQS; i++)
|
|
ks_dw_app_writel(ks_pcie, IRQ_ENABLE_SET + (i << 4), 0x1);
|
|
}
|
|
|
|
void ks_dw_pcie_handle_legacy_irq(struct keystone_pcie *ks_pcie, int offset)
|
|
{
|
|
struct pcie_port *pp = &ks_pcie->pp;
|
|
struct device *dev = pp->dev;
|
|
u32 pending;
|
|
int virq;
|
|
|
|
pending = ks_dw_app_readl(ks_pcie, IRQ_STATUS + (offset << 4));
|
|
|
|
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 */
|
|
ks_dw_app_writel(ks_pcie, IRQ_EOI, offset);
|
|
}
|
|
|
|
void ks_dw_pcie_enable_error_irq(struct keystone_pcie *ks_pcie)
|
|
{
|
|
ks_dw_app_writel(ks_pcie, ERR_IRQ_ENABLE_SET, ERR_IRQ_ALL);
|
|
}
|
|
|
|
irqreturn_t ks_dw_pcie_handle_error_irq(struct keystone_pcie *ks_pcie)
|
|
{
|
|
u32 status;
|
|
|
|
status = ks_dw_app_readl(ks_pcie, ERR_IRQ_STATUS_RAW) & ERR_IRQ_ALL;
|
|
if (!status)
|
|
return IRQ_NONE;
|
|
|
|
if (status & ERR_FATAL_IRQ)
|
|
dev_err(ks_pcie->pp.dev, "fatal error (status %#010x)\n",
|
|
status);
|
|
|
|
/* Ack the IRQ; status bits are RW1C */
|
|
ks_dw_app_writel(ks_pcie, ERR_IRQ_STATUS, status);
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static void ks_dw_pcie_ack_legacy_irq(struct irq_data *d)
|
|
{
|
|
}
|
|
|
|
static void ks_dw_pcie_mask_legacy_irq(struct irq_data *d)
|
|
{
|
|
}
|
|
|
|
static void ks_dw_pcie_unmask_legacy_irq(struct irq_data *d)
|
|
{
|
|
}
|
|
|
|
static struct irq_chip ks_dw_pcie_legacy_irq_chip = {
|
|
.name = "Keystone-PCI-Legacy-IRQ",
|
|
.irq_ack = ks_dw_pcie_ack_legacy_irq,
|
|
.irq_mask = ks_dw_pcie_mask_legacy_irq,
|
|
.irq_unmask = ks_dw_pcie_unmask_legacy_irq,
|
|
};
|
|
|
|
static int ks_dw_pcie_init_legacy_irq_map(struct irq_domain *d,
|
|
unsigned int irq, irq_hw_number_t hw_irq)
|
|
{
|
|
irq_set_chip_and_handler(irq, &ks_dw_pcie_legacy_irq_chip,
|
|
handle_level_irq);
|
|
irq_set_chip_data(irq, d->host_data);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct irq_domain_ops ks_dw_pcie_legacy_irq_domain_ops = {
|
|
.map = ks_dw_pcie_init_legacy_irq_map,
|
|
.xlate = irq_domain_xlate_onetwocell,
|
|
};
|
|
|
|
/**
|
|
* ks_dw_pcie_set_dbi_mode() - Set DBI mode to access overlaid BAR mask
|
|
* registers
|
|
*
|
|
* Since modification of dbi_cs2 involves different clock domain, read the
|
|
* status back to ensure the transition is complete.
|
|
*/
|
|
static void ks_dw_pcie_set_dbi_mode(struct keystone_pcie *ks_pcie)
|
|
{
|
|
u32 val;
|
|
|
|
val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
|
|
ks_dw_app_writel(ks_pcie, CMD_STATUS, DBI_CS2_EN_VAL | val);
|
|
|
|
do {
|
|
val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
|
|
} while (!(val & DBI_CS2_EN_VAL));
|
|
}
|
|
|
|
/**
|
|
* ks_dw_pcie_clear_dbi_mode() - Disable DBI mode
|
|
*
|
|
* Since modification of dbi_cs2 involves different clock domain, read the
|
|
* status back to ensure the transition is complete.
|
|
*/
|
|
static void ks_dw_pcie_clear_dbi_mode(struct keystone_pcie *ks_pcie)
|
|
{
|
|
u32 val;
|
|
|
|
val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
|
|
ks_dw_app_writel(ks_pcie, CMD_STATUS, ~DBI_CS2_EN_VAL & val);
|
|
|
|
do {
|
|
val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
|
|
} while (val & DBI_CS2_EN_VAL);
|
|
}
|
|
|
|
void ks_dw_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie)
|
|
{
|
|
struct pcie_port *pp = &ks_pcie->pp;
|
|
u32 start = pp->mem->start, end = pp->mem->end;
|
|
int i, tr_size;
|
|
u32 val;
|
|
|
|
/* Disable BARs for inbound access */
|
|
ks_dw_pcie_set_dbi_mode(ks_pcie);
|
|
dw_pcie_writel_rc(pp, PCI_BASE_ADDRESS_0, 0);
|
|
dw_pcie_writel_rc(pp, PCI_BASE_ADDRESS_1, 0);
|
|
ks_dw_pcie_clear_dbi_mode(ks_pcie);
|
|
|
|
/* Set outbound translation size per window division */
|
|
ks_dw_app_writel(ks_pcie, OB_SIZE, CFG_PCIM_WIN_SZ_IDX & 0x7);
|
|
|
|
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++) {
|
|
ks_dw_app_writel(ks_pcie, OB_OFFSET_INDEX(i), start | 1);
|
|
ks_dw_app_writel(ks_pcie, OB_OFFSET_HI(i), 0);
|
|
start += tr_size;
|
|
}
|
|
|
|
/* Enable OB translation */
|
|
val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
|
|
ks_dw_app_writel(ks_pcie, CMD_STATUS, OB_XLAT_EN_VAL | val);
|
|
}
|
|
|
|
/**
|
|
* 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 pcie_port *pp = &ks_pcie->pp;
|
|
u32 regval;
|
|
|
|
if (bus == 0)
|
|
return pp->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);
|
|
|
|
ks_dw_app_writel(ks_pcie, CFG_SETUP, regval);
|
|
return pp->va_cfg0_base;
|
|
}
|
|
|
|
int ks_dw_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus,
|
|
unsigned int devfn, int where, int size, u32 *val)
|
|
{
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
|
|
u8 bus_num = bus->number;
|
|
void __iomem *addr;
|
|
|
|
addr = ks_pcie_cfg_setup(ks_pcie, bus_num, devfn);
|
|
|
|
return dw_pcie_cfg_read(addr + where, size, val);
|
|
}
|
|
|
|
int ks_dw_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus,
|
|
unsigned int devfn, int where, int size, u32 val)
|
|
{
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
|
|
u8 bus_num = bus->number;
|
|
void __iomem *addr;
|
|
|
|
addr = ks_pcie_cfg_setup(ks_pcie, bus_num, devfn);
|
|
|
|
return dw_pcie_cfg_write(addr + where, size, val);
|
|
}
|
|
|
|
/**
|
|
* ks_dw_pcie_v3_65_scan_bus() - keystone scan_bus post initialization
|
|
*
|
|
* This sets BAR0 to enable inbound access for MSI_IRQ register
|
|
*/
|
|
void ks_dw_pcie_v3_65_scan_bus(struct pcie_port *pp)
|
|
{
|
|
struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
|
|
|
|
/* Configure and set up BAR0 */
|
|
ks_dw_pcie_set_dbi_mode(ks_pcie);
|
|
|
|
/* Enable BAR0 */
|
|
dw_pcie_writel_rc(pp, PCI_BASE_ADDRESS_0, 1);
|
|
dw_pcie_writel_rc(pp, PCI_BASE_ADDRESS_0, SZ_4K - 1);
|
|
|
|
ks_dw_pcie_clear_dbi_mode(ks_pcie);
|
|
|
|
/*
|
|
* For BAR0, just setting bus address for inbound writes (MSI) should
|
|
* be sufficient. Use physical address to avoid any conflicts.
|
|
*/
|
|
dw_pcie_writel_rc(pp, PCI_BASE_ADDRESS_0, ks_pcie->app.start);
|
|
}
|
|
|
|
/**
|
|
* ks_dw_pcie_link_up() - Check if link up
|
|
*/
|
|
int ks_dw_pcie_link_up(struct pcie_port *pp)
|
|
{
|
|
u32 val;
|
|
|
|
val = dw_pcie_readl_rc(pp, DEBUG0);
|
|
return (val & LTSSM_STATE_MASK) == LTSSM_STATE_L0;
|
|
}
|
|
|
|
void ks_dw_pcie_initiate_link_train(struct keystone_pcie *ks_pcie)
|
|
{
|
|
u32 val;
|
|
|
|
/* Disable Link training */
|
|
val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
|
|
val &= ~LTSSM_EN_VAL;
|
|
ks_dw_app_writel(ks_pcie, CMD_STATUS, val);
|
|
|
|
/* Initiate Link Training */
|
|
val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
|
|
ks_dw_app_writel(ks_pcie, CMD_STATUS, LTSSM_EN_VAL | val);
|
|
}
|
|
|
|
/**
|
|
* ks_dw_pcie_host_init() - initialize host for v3_65 dw hardware
|
|
*
|
|
* Ioremap the register resources, initialize legacy irq domain
|
|
* and call dw_pcie_v3_65_host_init() API to initialize the Keystone
|
|
* PCI host controller.
|
|
*/
|
|
int __init ks_dw_pcie_host_init(struct keystone_pcie *ks_pcie,
|
|
struct device_node *msi_intc_np)
|
|
{
|
|
struct pcie_port *pp = &ks_pcie->pp;
|
|
struct device *dev = pp->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);
|
|
pp->dbi_base = devm_ioremap_resource(dev, res);
|
|
if (IS_ERR(pp->dbi_base))
|
|
return PTR_ERR(pp->dbi_base);
|
|
|
|
/*
|
|
* We set these same and is used in pcie rd/wr_other_conf
|
|
* functions
|
|
*/
|
|
pp->va_cfg0_base = pp->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,
|
|
MAX_LEGACY_IRQS,
|
|
&ks_dw_pcie_legacy_irq_domain_ops,
|
|
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);
|
|
}
|