mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
0b8439d374
- Move IRQ register address computation inside macros (Kishon Vijay Abraham I) - Separate legacy IRQ and MSI configuration (Kishon Vijay Abraham I) - Use hwirq, not virq, to get MSI IRQ number offset (Kishon Vijay Abraham I) - Squash ks_pcie_handle_msi_irq() into ks_pcie_msi_irq_handler() (Kishon Vijay Abraham I) - Add dwc support for platforms with custom MSI controllers (Kishon Vijay Abraham I) - Add keystone-specific MSI controller (Kishon Vijay Abraham I) - Remove dwc host_ops previously used for keystone-specific MSI (Kishon Vijay Abraham I) - Skip dwc default MSI init if platform has custom MSI controller (Kishon Vijay Abraham I) - Implement .start_link() and .stop_link() for keystone endpoint support (Kishon Vijay Abraham I) - Add keystone "reg-names" DT binding (Kishon Vijay Abraham I) - Squash ks_pcie_dw_host_init() into ks_pcie_add_pcie_port() (Kishon Vijay Abraham I) - Get keystone register resources from DT by name, not index (Kishon Vijay Abraham I) - Get DT resources in .probe() to prepare for endpoint support (Kishon Vijay Abraham I) - Add "ti,syscon-pcie-mode" DT property for PCIe mode configuration (Kishon Vijay Abraham I) - Explicitly set keystone to host mode (Kishon Vijay Abraham I) - Document DT "atu" reg-names requirement for DesignWare core >= 4.80 (Kishon Vijay Abraham I) - Enable dwc iATU unroll for endpoint mode as well as host mode (Kishon Vijay Abraham I) - Add dwc "version" to identify core >= 4.80 for ATU programming (Kishon Vijay Abraham I) - Don't build ARM32-specific keystone code on ARM64 (Kishon Vijay Abraham I) - Add DT binding for keystone PCIe RC in AM654 SoC (Kishon Vijay Abraham I) - Add keystone support for AM654 SoC PCIe RC (Kishon Vijay Abraham I) - Reset keystone PHYs before enabling them (Kishon Vijay Abraham I) - Make of_pci_get_max_link_speed() available to endpoint drivers as well as host drivers (Kishon Vijay Abraham I) - Add keystone support for DT "max-link-speed" property (Kishon Vijay Abraham I) - Add endpoint library support for BAR buffer alignment (Kishon Vijay Abraham I) - Make all dw_pcie_ep_ops structs const (Kishon Vijay Abraham I) - Fix fencepost error in dw_pcie_ep_find_capability() (Kishon Vijay Abraham I) - Add dwc hooks for dbi/dbi2 that share the same address space (Kishon Vijay Abraham I) - Add keystone support for TI AM654x in endpoint mode (Kishon Vijay Abraham I) - Configure designware endpoints to advertise smallest resizable BAR (1MB) (Kishon Vijay Abraham I) - Align designware endpoint ATU windows for raising MSIs (Kishon Vijay Abraham I) - Add endpoint test support for TI AM654x (Kishon Vijay Abraham I) - Fix endpoint test test_reg_bar issue (Kishon Vijay Abraham I) * remotes/lorenzo/pci/keystone: misc: pci_endpoint_test: Fix test_reg_bar to be updated in pci_endpoint_test misc: pci_endpoint_test: Add support to test PCI EP in AM654x PCI: designware-ep: Use aligned ATU window for raising MSI interrupts PCI: designware-ep: Configure Resizable BAR cap to advertise the smallest size PCI: keystone: Add support for PCIe EP in AM654x Platforms dt-bindings: PCI: Add PCI EP DT binding documentation for AM654 PCI: dwc: Add callbacks for accessing dbi2 address space PCI: dwc: Fix dw_pcie_ep_find_capability() to return correct capability offset PCI: dwc: Add const qualifier to struct dw_pcie_ep_ops PCI: endpoint: Add support to specify alignment for buffers allocated to BARs PCI: keystone: Add support to set the max link speed from DT PCI: OF: Allow of_pci_get_max_link_speed() to be used by PCI Endpoint drivers PCI: keystone: Invoke phy_reset() API before enabling PHY PCI: keystone: Add support for PCIe RC in AM654x Platforms dt-bindings: PCI: Add PCI RC DT binding documentation for AM654 PCI: keystone: Prevent ARM32 specific code to be compiled for ARM64 PCI: dwc: Fix ATU identification for designware version >= 4.80 PCI: dwc: Enable iATU unroll for endpoint too dt-bindings: PCI: Document "atu" reg-names PCI: keystone: Explicitly set the PCIe mode dt-bindings: PCI: Add dt-binding to configure PCIe mode PCI: keystone: Move resources initialization to prepare for EP support PCI: keystone: Use platform_get_resource_byname() to get memory resources PCI: keystone: Perform host initialization in a single function dt-bindings: PCI: keystone: Add "reg-names" binding information PCI: keystone: Cleanup error_irq configuration PCI: keystone: Add start_link()/stop_link() dw_pcie_ops PCI: dwc: Remove default MSI initialization for platform specific MSI chips PCI: dwc: Remove Keystone specific dw_pcie_host_ops PCI: keystone: Use Keystone specific msi_irq_chip PCI: dwc: Add support to use non default msi_irq_chip PCI: keystone: Cleanup ks_pcie_msi_irq_handler() PCI: keystone: Use hwirq to get the MSI IRQ number offset PCI: keystone: Add separate functions for configuring MSI and legacy interrupt PCI: keystone: Cleanup interrupt related macros # Conflicts: # drivers/pci/controller/dwc/pcie-designware.h
441 lines
10 KiB
C
441 lines
10 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Synopsys DesignWare PCIe host controller driver
|
|
*
|
|
* Copyright (C) 2013 Samsung Electronics Co., Ltd.
|
|
* http://www.samsung.com
|
|
*
|
|
* Author: Jingoo Han <jg1.han@samsung.com>
|
|
*/
|
|
|
|
#include <linux/delay.h>
|
|
#include <linux/of.h>
|
|
#include <linux/types.h>
|
|
|
|
#include "pcie-designware.h"
|
|
|
|
int dw_pcie_read(void __iomem *addr, int size, u32 *val)
|
|
{
|
|
if (!IS_ALIGNED((uintptr_t)addr, size)) {
|
|
*val = 0;
|
|
return PCIBIOS_BAD_REGISTER_NUMBER;
|
|
}
|
|
|
|
if (size == 4) {
|
|
*val = readl(addr);
|
|
} else if (size == 2) {
|
|
*val = readw(addr);
|
|
} else if (size == 1) {
|
|
*val = readb(addr);
|
|
} else {
|
|
*val = 0;
|
|
return PCIBIOS_BAD_REGISTER_NUMBER;
|
|
}
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
}
|
|
|
|
int dw_pcie_write(void __iomem *addr, int size, u32 val)
|
|
{
|
|
if (!IS_ALIGNED((uintptr_t)addr, size))
|
|
return PCIBIOS_BAD_REGISTER_NUMBER;
|
|
|
|
if (size == 4)
|
|
writel(val, addr);
|
|
else if (size == 2)
|
|
writew(val, addr);
|
|
else if (size == 1)
|
|
writeb(val, addr);
|
|
else
|
|
return PCIBIOS_BAD_REGISTER_NUMBER;
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
}
|
|
|
|
u32 __dw_pcie_read_dbi(struct dw_pcie *pci, void __iomem *base, u32 reg,
|
|
size_t size)
|
|
{
|
|
int ret;
|
|
u32 val;
|
|
|
|
if (pci->ops->read_dbi)
|
|
return pci->ops->read_dbi(pci, base, reg, size);
|
|
|
|
ret = dw_pcie_read(base + reg, size, &val);
|
|
if (ret)
|
|
dev_err(pci->dev, "Read DBI address failed\n");
|
|
|
|
return val;
|
|
}
|
|
|
|
void __dw_pcie_write_dbi(struct dw_pcie *pci, void __iomem *base, u32 reg,
|
|
size_t size, u32 val)
|
|
{
|
|
int ret;
|
|
|
|
if (pci->ops->write_dbi) {
|
|
pci->ops->write_dbi(pci, base, reg, size, val);
|
|
return;
|
|
}
|
|
|
|
ret = dw_pcie_write(base + reg, size, val);
|
|
if (ret)
|
|
dev_err(pci->dev, "Write DBI address failed\n");
|
|
}
|
|
|
|
u32 __dw_pcie_read_dbi2(struct dw_pcie *pci, void __iomem *base, u32 reg,
|
|
size_t size)
|
|
{
|
|
int ret;
|
|
u32 val;
|
|
|
|
if (pci->ops->read_dbi2)
|
|
return pci->ops->read_dbi2(pci, base, reg, size);
|
|
|
|
ret = dw_pcie_read(base + reg, size, &val);
|
|
if (ret)
|
|
dev_err(pci->dev, "read DBI address failed\n");
|
|
|
|
return val;
|
|
}
|
|
|
|
void __dw_pcie_write_dbi2(struct dw_pcie *pci, void __iomem *base, u32 reg,
|
|
size_t size, u32 val)
|
|
{
|
|
int ret;
|
|
|
|
if (pci->ops->write_dbi2) {
|
|
pci->ops->write_dbi2(pci, base, reg, size, val);
|
|
return;
|
|
}
|
|
|
|
ret = dw_pcie_write(base + reg, size, val);
|
|
if (ret)
|
|
dev_err(pci->dev, "write DBI address failed\n");
|
|
}
|
|
|
|
static u32 dw_pcie_readl_ob_unroll(struct dw_pcie *pci, u32 index, u32 reg)
|
|
{
|
|
u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index);
|
|
|
|
return dw_pcie_readl_atu(pci, offset + reg);
|
|
}
|
|
|
|
static void dw_pcie_writel_ob_unroll(struct dw_pcie *pci, u32 index, u32 reg,
|
|
u32 val)
|
|
{
|
|
u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index);
|
|
|
|
dw_pcie_writel_atu(pci, offset + reg, val);
|
|
}
|
|
|
|
static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,
|
|
int type, u64 cpu_addr,
|
|
u64 pci_addr, u32 size)
|
|
{
|
|
u32 retries, val;
|
|
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LOWER_BASE,
|
|
lower_32_bits(cpu_addr));
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_BASE,
|
|
upper_32_bits(cpu_addr));
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LIMIT,
|
|
lower_32_bits(cpu_addr + size - 1));
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LOWER_TARGET,
|
|
lower_32_bits(pci_addr));
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_TARGET,
|
|
upper_32_bits(pci_addr));
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL1,
|
|
type);
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL2,
|
|
PCIE_ATU_ENABLE);
|
|
|
|
/*
|
|
* Make sure ATU enable takes effect before any subsequent config
|
|
* and I/O accesses.
|
|
*/
|
|
for (retries = 0; retries < LINK_WAIT_MAX_IATU_RETRIES; retries++) {
|
|
val = dw_pcie_readl_ob_unroll(pci, index,
|
|
PCIE_ATU_UNR_REGION_CTRL2);
|
|
if (val & PCIE_ATU_ENABLE)
|
|
return;
|
|
|
|
mdelay(LINK_WAIT_IATU);
|
|
}
|
|
dev_err(pci->dev, "Outbound iATU is not being enabled\n");
|
|
}
|
|
|
|
void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index, int type,
|
|
u64 cpu_addr, u64 pci_addr, u32 size)
|
|
{
|
|
u32 retries, val;
|
|
|
|
if (pci->ops->cpu_addr_fixup)
|
|
cpu_addr = pci->ops->cpu_addr_fixup(pci, cpu_addr);
|
|
|
|
if (pci->iatu_unroll_enabled) {
|
|
dw_pcie_prog_outbound_atu_unroll(pci, index, type, cpu_addr,
|
|
pci_addr, size);
|
|
return;
|
|
}
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_VIEWPORT,
|
|
PCIE_ATU_REGION_OUTBOUND | index);
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_LOWER_BASE,
|
|
lower_32_bits(cpu_addr));
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_UPPER_BASE,
|
|
upper_32_bits(cpu_addr));
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_LIMIT,
|
|
lower_32_bits(cpu_addr + size - 1));
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_LOWER_TARGET,
|
|
lower_32_bits(pci_addr));
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_UPPER_TARGET,
|
|
upper_32_bits(pci_addr));
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_CR1, type);
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_CR2, PCIE_ATU_ENABLE);
|
|
|
|
/*
|
|
* Make sure ATU enable takes effect before any subsequent config
|
|
* and I/O accesses.
|
|
*/
|
|
for (retries = 0; retries < LINK_WAIT_MAX_IATU_RETRIES; retries++) {
|
|
val = dw_pcie_readl_dbi(pci, PCIE_ATU_CR2);
|
|
if (val & PCIE_ATU_ENABLE)
|
|
return;
|
|
|
|
mdelay(LINK_WAIT_IATU);
|
|
}
|
|
dev_err(pci->dev, "Outbound iATU is not being enabled\n");
|
|
}
|
|
|
|
static u32 dw_pcie_readl_ib_unroll(struct dw_pcie *pci, u32 index, u32 reg)
|
|
{
|
|
u32 offset = PCIE_GET_ATU_INB_UNR_REG_OFFSET(index);
|
|
|
|
return dw_pcie_readl_atu(pci, offset + reg);
|
|
}
|
|
|
|
static void dw_pcie_writel_ib_unroll(struct dw_pcie *pci, u32 index, u32 reg,
|
|
u32 val)
|
|
{
|
|
u32 offset = PCIE_GET_ATU_INB_UNR_REG_OFFSET(index);
|
|
|
|
dw_pcie_writel_atu(pci, offset + reg, val);
|
|
}
|
|
|
|
static int dw_pcie_prog_inbound_atu_unroll(struct dw_pcie *pci, int index,
|
|
int bar, u64 cpu_addr,
|
|
enum dw_pcie_as_type as_type)
|
|
{
|
|
int type;
|
|
u32 retries, val;
|
|
|
|
dw_pcie_writel_ib_unroll(pci, index, PCIE_ATU_UNR_LOWER_TARGET,
|
|
lower_32_bits(cpu_addr));
|
|
dw_pcie_writel_ib_unroll(pci, index, PCIE_ATU_UNR_UPPER_TARGET,
|
|
upper_32_bits(cpu_addr));
|
|
|
|
switch (as_type) {
|
|
case DW_PCIE_AS_MEM:
|
|
type = PCIE_ATU_TYPE_MEM;
|
|
break;
|
|
case DW_PCIE_AS_IO:
|
|
type = PCIE_ATU_TYPE_IO;
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
|
|
dw_pcie_writel_ib_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL1, type);
|
|
dw_pcie_writel_ib_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL2,
|
|
PCIE_ATU_ENABLE |
|
|
PCIE_ATU_BAR_MODE_ENABLE | (bar << 8));
|
|
|
|
/*
|
|
* Make sure ATU enable takes effect before any subsequent config
|
|
* and I/O accesses.
|
|
*/
|
|
for (retries = 0; retries < LINK_WAIT_MAX_IATU_RETRIES; retries++) {
|
|
val = dw_pcie_readl_ib_unroll(pci, index,
|
|
PCIE_ATU_UNR_REGION_CTRL2);
|
|
if (val & PCIE_ATU_ENABLE)
|
|
return 0;
|
|
|
|
mdelay(LINK_WAIT_IATU);
|
|
}
|
|
dev_err(pci->dev, "Inbound iATU is not being enabled\n");
|
|
|
|
return -EBUSY;
|
|
}
|
|
|
|
int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, int index, int bar,
|
|
u64 cpu_addr, enum dw_pcie_as_type as_type)
|
|
{
|
|
int type;
|
|
u32 retries, val;
|
|
|
|
if (pci->iatu_unroll_enabled)
|
|
return dw_pcie_prog_inbound_atu_unroll(pci, index, bar,
|
|
cpu_addr, as_type);
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_VIEWPORT, PCIE_ATU_REGION_INBOUND |
|
|
index);
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_LOWER_TARGET, lower_32_bits(cpu_addr));
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_UPPER_TARGET, upper_32_bits(cpu_addr));
|
|
|
|
switch (as_type) {
|
|
case DW_PCIE_AS_MEM:
|
|
type = PCIE_ATU_TYPE_MEM;
|
|
break;
|
|
case DW_PCIE_AS_IO:
|
|
type = PCIE_ATU_TYPE_IO;
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_CR1, type);
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_CR2, PCIE_ATU_ENABLE
|
|
| PCIE_ATU_BAR_MODE_ENABLE | (bar << 8));
|
|
|
|
/*
|
|
* Make sure ATU enable takes effect before any subsequent config
|
|
* and I/O accesses.
|
|
*/
|
|
for (retries = 0; retries < LINK_WAIT_MAX_IATU_RETRIES; retries++) {
|
|
val = dw_pcie_readl_dbi(pci, PCIE_ATU_CR2);
|
|
if (val & PCIE_ATU_ENABLE)
|
|
return 0;
|
|
|
|
mdelay(LINK_WAIT_IATU);
|
|
}
|
|
dev_err(pci->dev, "Inbound iATU is not being enabled\n");
|
|
|
|
return -EBUSY;
|
|
}
|
|
|
|
void dw_pcie_disable_atu(struct dw_pcie *pci, int index,
|
|
enum dw_pcie_region_type type)
|
|
{
|
|
int region;
|
|
|
|
switch (type) {
|
|
case DW_PCIE_REGION_INBOUND:
|
|
region = PCIE_ATU_REGION_INBOUND;
|
|
break;
|
|
case DW_PCIE_REGION_OUTBOUND:
|
|
region = PCIE_ATU_REGION_OUTBOUND;
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_VIEWPORT, region | index);
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_CR2, (u32)~PCIE_ATU_ENABLE);
|
|
}
|
|
|
|
int dw_pcie_wait_for_link(struct dw_pcie *pci)
|
|
{
|
|
int retries;
|
|
|
|
/* Check if the link is up or not */
|
|
for (retries = 0; retries < LINK_WAIT_MAX_RETRIES; retries++) {
|
|
if (dw_pcie_link_up(pci)) {
|
|
dev_info(pci->dev, "Link up\n");
|
|
return 0;
|
|
}
|
|
usleep_range(LINK_WAIT_USLEEP_MIN, LINK_WAIT_USLEEP_MAX);
|
|
}
|
|
|
|
dev_err(pci->dev, "Phy link never came up\n");
|
|
|
|
return -ETIMEDOUT;
|
|
}
|
|
|
|
int dw_pcie_link_up(struct dw_pcie *pci)
|
|
{
|
|
u32 val;
|
|
|
|
if (pci->ops->link_up)
|
|
return pci->ops->link_up(pci);
|
|
|
|
val = readl(pci->dbi_base + PCIE_PORT_DEBUG1);
|
|
return ((val & PCIE_PORT_DEBUG1_LINK_UP) &&
|
|
(!(val & PCIE_PORT_DEBUG1_LINK_IN_TRAINING)));
|
|
}
|
|
|
|
static u8 dw_pcie_iatu_unroll_enabled(struct dw_pcie *pci)
|
|
{
|
|
u32 val;
|
|
|
|
val = dw_pcie_readl_dbi(pci, PCIE_ATU_VIEWPORT);
|
|
if (val == 0xffffffff)
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void dw_pcie_setup(struct dw_pcie *pci)
|
|
{
|
|
int ret;
|
|
u32 val;
|
|
u32 lanes;
|
|
struct device *dev = pci->dev;
|
|
struct device_node *np = dev->of_node;
|
|
|
|
if (pci->version >= 0x480A || (!pci->version &&
|
|
dw_pcie_iatu_unroll_enabled(pci))) {
|
|
pci->iatu_unroll_enabled = true;
|
|
if (!pci->atu_base)
|
|
pci->atu_base = pci->dbi_base + DEFAULT_DBI_ATU_OFFSET;
|
|
}
|
|
dev_dbg(pci->dev, "iATU unroll: %s\n", pci->iatu_unroll_enabled ?
|
|
"enabled" : "disabled");
|
|
|
|
|
|
ret = of_property_read_u32(np, "num-lanes", &lanes);
|
|
if (ret)
|
|
lanes = 0;
|
|
|
|
/* Set the number of lanes */
|
|
val = dw_pcie_readl_dbi(pci, PCIE_PORT_LINK_CONTROL);
|
|
val &= ~PORT_LINK_MODE_MASK;
|
|
switch (lanes) {
|
|
case 1:
|
|
val |= PORT_LINK_MODE_1_LANES;
|
|
break;
|
|
case 2:
|
|
val |= PORT_LINK_MODE_2_LANES;
|
|
break;
|
|
case 4:
|
|
val |= PORT_LINK_MODE_4_LANES;
|
|
break;
|
|
case 8:
|
|
val |= PORT_LINK_MODE_8_LANES;
|
|
break;
|
|
default:
|
|
dev_err(pci->dev, "num-lanes %u: invalid value\n", lanes);
|
|
return;
|
|
}
|
|
dw_pcie_writel_dbi(pci, PCIE_PORT_LINK_CONTROL, val);
|
|
|
|
/* Set link width speed control register */
|
|
val = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
|
|
val &= ~PORT_LOGIC_LINK_WIDTH_MASK;
|
|
switch (lanes) {
|
|
case 1:
|
|
val |= PORT_LOGIC_LINK_WIDTH_1_LANES;
|
|
break;
|
|
case 2:
|
|
val |= PORT_LOGIC_LINK_WIDTH_2_LANES;
|
|
break;
|
|
case 4:
|
|
val |= PORT_LOGIC_LINK_WIDTH_4_LANES;
|
|
break;
|
|
case 8:
|
|
val |= PORT_LOGIC_LINK_WIDTH_8_LANES;
|
|
break;
|
|
}
|
|
dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, val);
|
|
}
|