mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2025-02-23 11:00:09 +07:00

- Use pci_host_bridge.windows list directly instead of splicing in a temporary list for cadence, mvebu, host-common (Rob Herring) - Use pci_host_probe() instead of open-coding all the pieces for altera, brcmstb, iproc, mobiveil, rcar, rockchip, tegra, v3, versatile, xgene, xilinx, xilinx-nwl (Rob Herring) - Convert to devm_platform_ioremap_resource_byname() instead of open-coding platform_get_resource_byname() and devm_ioremap_resource() for altera, cadence, mediatek, rockchip, tegra, xgene (Dejin Zheng) - Convert to devm_platform_ioremap_resource() instead of open-coding platform_get_resource() and devm_ioremap_resource() for aardvark, brcmstb, exynos, ftpci100, versatile (Dejin Zheng) - Remove redundant error messages from devm_pci_remap_cfg_resource() callers (Dejin Zheng) - Drop useless PCI_ENABLE_PROC_DOMAINS from versatile driver (Rob Herring) - Default host bridge parent device to the platform device (Rob Herring) - Drop unnecessary zeroing of host bridge fields (Rob Herring) - Use pci_is_root_bus() instead of tracking root bus number separately in aardvark, designware (imx6, keystone, designware-host), mobiveil, xilinx-nwl, xilinx, rockchip, rcar (Rob Herring) - Set host bridge bus number in pci_scan_root_bus_bridge() instead of each driver for aardvark, designware-host, host-common, mediatek, rcar, tegra, v3-semi (Rob Herring) - Use bridge resources instead of parsing DT 'ranges' again for cadence (Rob Herring) - Remove private bus number and range from cadence (Rob Herring) - Use devm_pci_alloc_host_bridge() to simplify rcar (Rob Herring) - Use struct pci_host_bridge.windows list directly rather than a temporary (Rob Herring) - Reduce OF "missing non-prefetchable window" from error to warning message (Rob Herring) - Convert rcar-gen2 from old Arm-specific pci_common_init_dev() to new arch-independent interfaces (Rob Herring) - Move DT resource setup into devm_pci_alloc_host_bridge() (Rob Herring) - Set bridge map_irq and swizzle_irq to default functions; drivers that don't support legacy IRQs (iproc) need to undo this (Rob Herring) * pci/host-probe-refactor: PCI: Set bridge map_irq and swizzle_irq to default functions PCI: Move DT resource setup into devm_pci_alloc_host_bridge() PCI: rcar-gen2: Convert to use modern host bridge probe functions PCI: of: Reduce missing non-prefetchable memory region to a warning PCI: rcar: Use struct pci_host_bridge.windows list directly PCI: rcar: Use devm_pci_alloc_host_bridge() PCI: cadence: Remove private bus number and range storage PCI: cadence: Use bridge resources for outbound window setup PCI: Move setting pci_host_bridge.busnr out of host drivers PCI: rcar: Use pci_is_root_bus() to check if bus is root bus PCI: rockchip: Use pci_is_root_bus() to check if bus is root bus PCI: xilinx: Use pci_is_root_bus() to check if bus is root bus PCI: xilinx-nwl: Use pci_is_root_bus() to check if bus is root bus PCI: mobiveil: Use pci_is_root_bus() to check if bus is root bus PCI: designware: Use pci_is_root_bus() to check if bus is root bus PCI: aardvark: Use pci_is_root_bus() to check if bus is root bus PCI: Drop unnecessary zeroing of bridge fields PCI: Set default bridge parent device PCI: versatile: Drop flag PCI_ENABLE_PROC_DOMAINS PCI: controller: Remove duplicate error message PCI: controller: Convert to devm_platform_ioremap_resource() PCI: controller: Convert to devm_platform_ioremap_resource_byname() PCI: xilinx: Use pci_host_probe() to register host PCI: xilinx-nwl: Use pci_host_probe() to register host PCI: rockchip: Use pci_host_probe() to register host PCI: rcar: Use pci_host_probe() to register host PCI: iproc: Use pci_host_probe() to register host PCI: altera: Use pci_host_probe() to register host PCI: xgene: Use pci_host_probe() to register host PCI: versatile: Use pci_host_probe() to register host PCI: v3: Use pci_host_probe() to register host PCI: tegra: Use pci_host_probe() to register host PCI: mobiveil: Use pci_host_probe() to register host PCI: brcmstb: Use pci_host_probe() to register host PCI: host-common: Use struct pci_host_bridge.windows list directly PCI: mvebu: Use struct pci_host_bridge.windows list directly PCI: cadence: Use struct pci_host_bridge.windows list directly # Conflicts: # drivers/pci/controller/cadence/pcie-cadence-host.c
259 lines
6.6 KiB
C
259 lines
6.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
// Copyright (c) 2017 Cadence
|
|
// Cadence PCIe controller driver.
|
|
// Author: Cyrille Pitchen <cyrille.pitchen@free-electrons.com>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include "pcie-cadence.h"
|
|
|
|
void cdns_pcie_set_outbound_region(struct cdns_pcie *pcie, u8 busnr, u8 fn,
|
|
u32 r, bool is_io,
|
|
u64 cpu_addr, u64 pci_addr, size_t size)
|
|
{
|
|
/*
|
|
* roundup_pow_of_two() returns an unsigned long, which is not suited
|
|
* for 64bit values.
|
|
*/
|
|
u64 sz = 1ULL << fls64(size - 1);
|
|
int nbits = ilog2(sz);
|
|
u32 addr0, addr1, desc0, desc1;
|
|
|
|
if (nbits < 8)
|
|
nbits = 8;
|
|
|
|
/* Set the PCI address */
|
|
addr0 = CDNS_PCIE_AT_OB_REGION_PCI_ADDR0_NBITS(nbits) |
|
|
(lower_32_bits(pci_addr) & GENMASK(31, 8));
|
|
addr1 = upper_32_bits(pci_addr);
|
|
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR0(r), addr0);
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR1(r), addr1);
|
|
|
|
/* Set the PCIe header descriptor */
|
|
if (is_io)
|
|
desc0 = CDNS_PCIE_AT_OB_REGION_DESC0_TYPE_IO;
|
|
else
|
|
desc0 = CDNS_PCIE_AT_OB_REGION_DESC0_TYPE_MEM;
|
|
desc1 = 0;
|
|
|
|
/*
|
|
* Whatever Bit [23] is set or not inside DESC0 register of the outbound
|
|
* PCIe descriptor, the PCI function number must be set into
|
|
* Bits [26:24] of DESC0 anyway.
|
|
*
|
|
* In Root Complex mode, the function number is always 0 but in Endpoint
|
|
* mode, the PCIe controller may support more than one function. This
|
|
* function number needs to be set properly into the outbound PCIe
|
|
* descriptor.
|
|
*
|
|
* Besides, setting Bit [23] is mandatory when in Root Complex mode:
|
|
* then the driver must provide the bus, resp. device, number in
|
|
* Bits [7:0] of DESC1, resp. Bits[31:27] of DESC0. Like the function
|
|
* number, the device number is always 0 in Root Complex mode.
|
|
*
|
|
* However when in Endpoint mode, we can clear Bit [23] of DESC0, hence
|
|
* the PCIe controller will use the captured values for the bus and
|
|
* device numbers.
|
|
*/
|
|
if (pcie->is_rc) {
|
|
/* The device and function numbers are always 0. */
|
|
desc0 |= CDNS_PCIE_AT_OB_REGION_DESC0_HARDCODED_RID |
|
|
CDNS_PCIE_AT_OB_REGION_DESC0_DEVFN(0);
|
|
desc1 |= CDNS_PCIE_AT_OB_REGION_DESC1_BUS(busnr);
|
|
} else {
|
|
/*
|
|
* Use captured values for bus and device numbers but still
|
|
* need to set the function number.
|
|
*/
|
|
desc0 |= CDNS_PCIE_AT_OB_REGION_DESC0_DEVFN(fn);
|
|
}
|
|
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC0(r), desc0);
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(r), desc1);
|
|
|
|
/* Set the CPU address */
|
|
if (pcie->ops->cpu_addr_fixup)
|
|
cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr);
|
|
|
|
addr0 = CDNS_PCIE_AT_OB_REGION_CPU_ADDR0_NBITS(nbits) |
|
|
(lower_32_bits(cpu_addr) & GENMASK(31, 8));
|
|
addr1 = upper_32_bits(cpu_addr);
|
|
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR0(r), addr0);
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR1(r), addr1);
|
|
}
|
|
|
|
void cdns_pcie_set_outbound_region_for_normal_msg(struct cdns_pcie *pcie,
|
|
u8 busnr, u8 fn,
|
|
u32 r, u64 cpu_addr)
|
|
{
|
|
u32 addr0, addr1, desc0, desc1;
|
|
|
|
desc0 = CDNS_PCIE_AT_OB_REGION_DESC0_TYPE_NORMAL_MSG;
|
|
desc1 = 0;
|
|
|
|
/* See cdns_pcie_set_outbound_region() comments above. */
|
|
if (pcie->is_rc) {
|
|
desc0 |= CDNS_PCIE_AT_OB_REGION_DESC0_HARDCODED_RID |
|
|
CDNS_PCIE_AT_OB_REGION_DESC0_DEVFN(0);
|
|
desc1 |= CDNS_PCIE_AT_OB_REGION_DESC1_BUS(busnr);
|
|
} else {
|
|
desc0 |= CDNS_PCIE_AT_OB_REGION_DESC0_DEVFN(fn);
|
|
}
|
|
|
|
/* Set the CPU address */
|
|
if (pcie->ops->cpu_addr_fixup)
|
|
cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr);
|
|
|
|
addr0 = CDNS_PCIE_AT_OB_REGION_CPU_ADDR0_NBITS(17) |
|
|
(lower_32_bits(cpu_addr) & GENMASK(31, 8));
|
|
addr1 = upper_32_bits(cpu_addr);
|
|
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR0(r), 0);
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR1(r), 0);
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC0(r), desc0);
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(r), desc1);
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR0(r), addr0);
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR1(r), addr1);
|
|
}
|
|
|
|
void cdns_pcie_reset_outbound_region(struct cdns_pcie *pcie, u32 r)
|
|
{
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR0(r), 0);
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR1(r), 0);
|
|
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC0(r), 0);
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(r), 0);
|
|
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR0(r), 0);
|
|
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR1(r), 0);
|
|
}
|
|
|
|
void cdns_pcie_disable_phy(struct cdns_pcie *pcie)
|
|
{
|
|
int i = pcie->phy_count;
|
|
|
|
while (i--) {
|
|
phy_power_off(pcie->phy[i]);
|
|
phy_exit(pcie->phy[i]);
|
|
}
|
|
}
|
|
|
|
int cdns_pcie_enable_phy(struct cdns_pcie *pcie)
|
|
{
|
|
int ret;
|
|
int i;
|
|
|
|
for (i = 0; i < pcie->phy_count; i++) {
|
|
ret = phy_init(pcie->phy[i]);
|
|
if (ret < 0)
|
|
goto err_phy;
|
|
|
|
ret = phy_power_on(pcie->phy[i]);
|
|
if (ret < 0) {
|
|
phy_exit(pcie->phy[i]);
|
|
goto err_phy;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
|
|
err_phy:
|
|
while (--i >= 0) {
|
|
phy_power_off(pcie->phy[i]);
|
|
phy_exit(pcie->phy[i]);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
int cdns_pcie_init_phy(struct device *dev, struct cdns_pcie *pcie)
|
|
{
|
|
struct device_node *np = dev->of_node;
|
|
int phy_count;
|
|
struct phy **phy;
|
|
struct device_link **link;
|
|
int i;
|
|
int ret;
|
|
const char *name;
|
|
|
|
phy_count = of_property_count_strings(np, "phy-names");
|
|
if (phy_count < 1) {
|
|
dev_err(dev, "no phy-names. PHY will not be initialized\n");
|
|
pcie->phy_count = 0;
|
|
return 0;
|
|
}
|
|
|
|
phy = devm_kcalloc(dev, phy_count, sizeof(*phy), GFP_KERNEL);
|
|
if (!phy)
|
|
return -ENOMEM;
|
|
|
|
link = devm_kcalloc(dev, phy_count, sizeof(*link), GFP_KERNEL);
|
|
if (!link)
|
|
return -ENOMEM;
|
|
|
|
for (i = 0; i < phy_count; i++) {
|
|
of_property_read_string_index(np, "phy-names", i, &name);
|
|
phy[i] = devm_phy_get(dev, name);
|
|
if (IS_ERR(phy[i])) {
|
|
ret = PTR_ERR(phy[i]);
|
|
goto err_phy;
|
|
}
|
|
link[i] = device_link_add(dev, &phy[i]->dev, DL_FLAG_STATELESS);
|
|
if (!link[i]) {
|
|
devm_phy_put(dev, phy[i]);
|
|
ret = -EINVAL;
|
|
goto err_phy;
|
|
}
|
|
}
|
|
|
|
pcie->phy_count = phy_count;
|
|
pcie->phy = phy;
|
|
pcie->link = link;
|
|
|
|
ret = cdns_pcie_enable_phy(pcie);
|
|
if (ret)
|
|
goto err_phy;
|
|
|
|
return 0;
|
|
|
|
err_phy:
|
|
while (--i >= 0) {
|
|
device_link_del(link[i]);
|
|
devm_phy_put(dev, phy[i]);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
static int cdns_pcie_suspend_noirq(struct device *dev)
|
|
{
|
|
struct cdns_pcie *pcie = dev_get_drvdata(dev);
|
|
|
|
cdns_pcie_disable_phy(pcie);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int cdns_pcie_resume_noirq(struct device *dev)
|
|
{
|
|
struct cdns_pcie *pcie = dev_get_drvdata(dev);
|
|
int ret;
|
|
|
|
ret = cdns_pcie_enable_phy(pcie);
|
|
if (ret) {
|
|
dev_err(dev, "failed to enable phy\n");
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
const struct dev_pm_ops cdns_pcie_pm_ops = {
|
|
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(cdns_pcie_suspend_noirq,
|
|
cdns_pcie_resume_noirq)
|
|
};
|