Lines Matching +full:ecam +full:- +full:based
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2014 Hauke Mehrtens <hauke@hauke-m.de>
9 #include <linux/pci-ecam.h>
17 #include <linux/irqchip/arm-gic-v3.h>
25 #include "pcie-iproc.h"
92 * struct iproc_pcie_ob_map - iProc PCIe outbound mapping controller-specific
139 * enum iproc_pcie_ib_map_type - iProc PCIe inbound mapping type
151 * struct iproc_pcie_ib_map - iProc PCIe inbound mapping controller-specific
160 * @imap_addr_offset: register offset between the upper and lower 32-bit
401 struct iproc_pcie *pcie = bus->sysdata; in iproc_data()
413 return pcie->reg_offsets[reg]; in iproc_pcie_reg_offset()
424 return readl(pcie->base + offset); in iproc_pcie_read_reg()
435 writel(val, pcie->base + offset); in iproc_pcie_write_reg()
441 * (typically seen during enumeration with multi-function devices) from
450 if (bus->number && pcie->has_apb_err_disable) { in iproc_pcie_apb_err_disable()
478 return (pcie->base + offset); in iproc_pcie_map_ep_cfg_reg()
500 * Note that a non-Vendor ID config register may have a value of in iproc_pcie_cfg_retry()
506 while (data == CFG_RETRY_STATUS && timeout--) { in iproc_pcie_cfg_retry()
540 pcie->fix_paxc_cap = true; in iproc_pcie_fix_cap()
544 if (pcie->fix_paxc_cap) { in iproc_pcie_fix_cap()
552 if (pcie->fix_paxc_cap) { in iproc_pcie_fix_cap()
573 unsigned int busno = bus->number; in iproc_pcie_config_read()
596 *val = (data >> (8 * (where & 3))) & ((1 << (size * 8)) - 1); in iproc_pcie_config_read()
611 if (pcie->rej_unconfig_pf && in iproc_pcie_config_read()
641 return (pcie->base + offset); in iproc_pcie_map_cfg_bus()
651 return iproc_pcie_map_cfg_bus(iproc_data(bus), bus->number, devfn, in iproc_pcie_bus_map_cfg_bus()
668 *val = (*val >> (8 * (where & 3))) & ((1 << (size * 8)) - 1); in iproc_pci_raw_config_read32()
689 mask = ~(((1 << (size * 8)) - 1) << ((where & 0x3) * 8)); in iproc_pci_raw_config_write32()
704 if (pcie->iproc_cfg_read) in iproc_pcie_config_read32()
740 if (pcie->ep_is_internal) in iproc_pcie_perst_ctrl()
768 struct device *dev = pcie->dev; in iproc_pcie_check_link()
776 if (pcie->ep_is_internal) in iproc_pcie_check_link()
782 return -ENODEV; in iproc_pcie_check_link()
789 return -EFAULT; in iproc_pcie_check_link()
835 return link_is_active ? 0 : -ENODEV; in iproc_pcie_check_link()
856 struct device *dev = pcie->dev; in iproc_pcie_ob_write()
860 * Derive the OARR/OMAP offset from the first pair (OARR0/OMAP0) based in iproc_pcie_ob_write()
869 return -EINVAL; in iproc_pcie_ob_write()
872 * Program the OARR registers. The upper 32-bit OARR register is in iproc_pcie_ob_write()
873 * always right after the lower 32-bit OARR register. in iproc_pcie_ob_write()
876 OARR_VALID, pcie->base + oarr_offset); in iproc_pcie_ob_write()
877 writel(upper_32_bits(axi_addr), pcie->base + oarr_offset + 4); in iproc_pcie_ob_write()
880 writel(lower_32_bits(pci_addr), pcie->base + omap_offset); in iproc_pcie_ob_write()
881 writel(upper_32_bits(pci_addr), pcie->base + omap_offset + 4); in iproc_pcie_ob_write()
886 readl(pcie->base + oarr_offset), in iproc_pcie_ob_write()
887 readl(pcie->base + oarr_offset + 4)); in iproc_pcie_ob_write()
889 readl(pcie->base + omap_offset), in iproc_pcie_ob_write()
890 readl(pcie->base + omap_offset + 4)); in iproc_pcie_ob_write()
900 * iproc_pcie_address = axi_address - axi_offset
904 * axi_addr -> iproc_pcie_address -> OARR -> OMAP -> pci_address
909 struct iproc_pcie_ob *ob = &pcie->ob; in iproc_pcie_setup_ob()
910 struct device *dev = pcie->dev; in iproc_pcie_setup_ob()
911 int ret = -EINVAL, window_idx, size_idx; in iproc_pcie_setup_ob()
913 if (axi_addr < ob->axi_offset) { in iproc_pcie_setup_ob()
915 &axi_addr, &ob->axi_offset); in iproc_pcie_setup_ob()
916 return -EINVAL; in iproc_pcie_setup_ob()
923 axi_addr -= ob->axi_offset; in iproc_pcie_setup_ob()
926 for (window_idx = ob->nr_windows - 1; window_idx >= 0; window_idx--) { in iproc_pcie_setup_ob()
928 &pcie->ob_map[window_idx]; in iproc_pcie_setup_ob()
942 for (size_idx = ob_map->nr_sizes - 1; size_idx >= 0; in iproc_pcie_setup_ob()
943 size_idx--) { in iproc_pcie_setup_ob()
945 ob_map->window_sizes[size_idx] * SZ_1M; in iproc_pcie_setup_ob()
972 return -EINVAL; in iproc_pcie_setup_ob()
984 size -= window_size; in iproc_pcie_setup_ob()
1003 &axi_addr, &ob->axi_offset, &pci_addr, &size); in iproc_pcie_setup_ob()
1011 struct device *dev = pcie->dev; in iproc_pcie_map_ranges()
1016 struct resource *res = window->res; in iproc_pcie_map_ranges()
1024 ret = iproc_pcie_setup_ob(pcie, res->start, in iproc_pcie_map_ranges()
1025 res->start - window->offset, in iproc_pcie_map_ranges()
1032 return -EINVAL; in iproc_pcie_map_ranges()
1042 const struct iproc_pcie_ib_map *ib_map = &pcie->ib_map[region_idx]; in iproc_pcie_ib_is_in_use()
1047 return !!(val & (BIT(ib_map->nr_sizes) - 1)); in iproc_pcie_ib_is_in_use()
1053 return !!(ib_map->type == type); in iproc_pcie_ib_check_type()
1060 struct device *dev = pcie->dev; in iproc_pcie_ib_write()
1061 const struct iproc_pcie_ib_map *ib_map = &pcie->ib_map[region_idx]; in iproc_pcie_ib_write()
1072 return -EINVAL; in iproc_pcie_ib_write()
1078 * Program the IARR registers. The upper 32-bit IARR register is in iproc_pcie_ib_write()
1079 * always right after the lower 32-bit IARR register. in iproc_pcie_ib_write()
1082 pcie->base + iarr_offset); in iproc_pcie_ib_write()
1083 writel(upper_32_bits(pci_addr), pcie->base + iarr_offset + 4); in iproc_pcie_ib_write()
1086 readl(pcie->base + iarr_offset), in iproc_pcie_ib_write()
1087 readl(pcie->base + iarr_offset + 4)); in iproc_pcie_ib_write()
1095 val = readl(pcie->base + imap_offset); in iproc_pcie_ib_write()
1097 writel(val, pcie->base + imap_offset); in iproc_pcie_ib_write()
1099 pcie->base + imap_offset + ib_map->imap_addr_offset); in iproc_pcie_ib_write()
1102 window_idx, readl(pcie->base + imap_offset), in iproc_pcie_ib_write()
1103 readl(pcie->base + imap_offset + in iproc_pcie_ib_write()
1104 ib_map->imap_addr_offset)); in iproc_pcie_ib_write()
1106 imap_offset += ib_map->imap_window_offset; in iproc_pcie_ib_write()
1117 struct device *dev = pcie->dev; in iproc_pcie_setup_ib()
1118 struct iproc_pcie_ib *ib = &pcie->ib; in iproc_pcie_setup_ib()
1121 u64 axi_addr = entry->res->start; in iproc_pcie_setup_ib()
1122 u64 pci_addr = entry->res->start - entry->offset; in iproc_pcie_setup_ib()
1123 resource_size_t size = resource_size(entry->res); in iproc_pcie_setup_ib()
1126 for (region_idx = 0; region_idx < ib->nr_regions; region_idx++) { in iproc_pcie_setup_ib()
1128 &pcie->ib_map[region_idx]; in iproc_pcie_setup_ib()
1139 for (size_idx = 0; size_idx < ib_map->nr_sizes; size_idx++) { in iproc_pcie_setup_ib()
1141 ib_map->region_sizes[size_idx] * ib_map->size_unit; in iproc_pcie_setup_ib()
1151 return -EINVAL; in iproc_pcie_setup_ib()
1156 ib_map->nr_windows, axi_addr, in iproc_pcie_setup_ib()
1165 ret = -EINVAL; in iproc_pcie_setup_ib()
1181 resource_list_for_each_entry(entry, &host->dma_ranges) { in iproc_pcie_map_dma_ranges()
1193 struct iproc_pcie_ib *ib = &pcie->ib; in iproc_pcie_invalidate_mapping()
1194 struct iproc_pcie_ob *ob = &pcie->ob; in iproc_pcie_invalidate_mapping()
1197 if (pcie->ep_is_internal) in iproc_pcie_invalidate_mapping()
1200 if (pcie->need_ob_cfg) { in iproc_pcie_invalidate_mapping()
1202 for (idx = ob->nr_windows - 1; idx >= 0; idx--) { in iproc_pcie_invalidate_mapping()
1208 if (pcie->need_ib_cfg) { in iproc_pcie_invalidate_mapping()
1210 for (idx = 0; idx < ib->nr_regions; idx++) { in iproc_pcie_invalidate_mapping()
1221 struct device *dev = pcie->dev; in iproce_pcie_get_msi()
1226 * Check if 'msi-map' points to ARM GICv3 ITS, which is the only in iproce_pcie_get_msi()
1229 if (!of_device_is_compatible(msi_node, "arm,gic-v3-its")) { in iproce_pcie_get_msi()
1231 return -ENODEV; in iproce_pcie_get_msi()
1253 msi_addr &= ~(SZ_32K - 1); in iproc_pcie_paxb_v2_msi_steer()
1254 entry.res->start = msi_addr; in iproc_pcie_paxb_v2_msi_steer()
1255 entry.res->end = msi_addr + SZ_32K - 1; in iproc_pcie_paxb_v2_msi_steer()
1269 * treated as non-MSI transfers in iproc_pcie_paxc_v2_msi_steer()
1280 * based SoCs, all I/O register bases are well below the 32-bit in iproc_pcie_paxc_v2_msi_steer()
1313 struct device *dev = pcie->dev; in iproc_pcie_msi_steer()
1323 switch (pcie->type) { in iproc_pcie_msi_steer()
1333 return -EINVAL; in iproc_pcie_msi_steer()
1345 * Either the "msi-parent" or the "msi-map" phandle needs to exist in iproc_pcie_msi_enable()
1349 msi_node = of_parse_phandle(pcie->dev->of_node, "msi-parent", 0); in iproc_pcie_msi_enable()
1355 msi_map = of_get_property(pcie->dev->of_node, "msi-map", &len); in iproc_pcie_msi_enable()
1357 return -ENODEV; in iproc_pcie_msi_enable()
1362 return -ENODEV; in iproc_pcie_msi_enable()
1370 if (pcie->need_msi_steer) { in iproc_pcie_msi_enable()
1394 struct device *dev = pcie->dev; in iproc_pcie_rev_init()
1398 switch (pcie->type) { in iproc_pcie_rev_init()
1404 pcie->has_apb_err_disable = true; in iproc_pcie_rev_init()
1405 if (pcie->need_ob_cfg) { in iproc_pcie_rev_init()
1406 pcie->ob_map = paxb_ob_map; in iproc_pcie_rev_init()
1407 pcie->ob.nr_windows = ARRAY_SIZE(paxb_ob_map); in iproc_pcie_rev_init()
1412 pcie->iproc_cfg_read = true; in iproc_pcie_rev_init()
1413 pcie->has_apb_err_disable = true; in iproc_pcie_rev_init()
1414 if (pcie->need_ob_cfg) { in iproc_pcie_rev_init()
1415 pcie->ob_map = paxb_v2_ob_map; in iproc_pcie_rev_init()
1416 pcie->ob.nr_windows = ARRAY_SIZE(paxb_v2_ob_map); in iproc_pcie_rev_init()
1418 pcie->ib.nr_regions = ARRAY_SIZE(paxb_v2_ib_map); in iproc_pcie_rev_init()
1419 pcie->ib_map = paxb_v2_ib_map; in iproc_pcie_rev_init()
1420 pcie->need_msi_steer = true; in iproc_pcie_rev_init()
1426 pcie->ep_is_internal = true; in iproc_pcie_rev_init()
1427 pcie->iproc_cfg_read = true; in iproc_pcie_rev_init()
1428 pcie->rej_unconfig_pf = true; in iproc_pcie_rev_init()
1432 pcie->ep_is_internal = true; in iproc_pcie_rev_init()
1433 pcie->iproc_cfg_read = true; in iproc_pcie_rev_init()
1434 pcie->rej_unconfig_pf = true; in iproc_pcie_rev_init()
1435 pcie->need_msi_steer = true; in iproc_pcie_rev_init()
1439 return -EINVAL; in iproc_pcie_rev_init()
1442 pcie->reg_offsets = devm_kcalloc(dev, IPROC_PCIE_MAX_NUM_REG, in iproc_pcie_rev_init()
1443 sizeof(*pcie->reg_offsets), in iproc_pcie_rev_init()
1445 if (!pcie->reg_offsets) in iproc_pcie_rev_init()
1446 return -ENOMEM; in iproc_pcie_rev_init()
1449 pcie->reg_offsets[0] = (pcie->type == IPROC_PCIE_PAXC_V2) ? in iproc_pcie_rev_init()
1452 pcie->reg_offsets[reg_idx] = regs[reg_idx] ? in iproc_pcie_rev_init()
1465 dev = pcie->dev; in iproc_pcie_setup()
1473 ret = phy_init(pcie->phy); in iproc_pcie_setup()
1479 ret = phy_power_on(pcie->phy); in iproc_pcie_setup()
1490 if (pcie->need_ob_cfg) { in iproc_pcie_setup()
1498 if (pcie->need_ib_cfg) { in iproc_pcie_setup()
1500 if (ret && ret != -ENOENT) in iproc_pcie_setup()
1516 host->ops = &iproc_pcie_ops; in iproc_pcie_setup()
1517 host->sysdata = pcie; in iproc_pcie_setup()
1518 host->map_irq = pcie->map_irq; in iproc_pcie_setup()
1526 for_each_pci_bridge(pdev, host->bus) { in iproc_pcie_setup()
1534 phy_power_off(pcie->phy); in iproc_pcie_setup()
1536 phy_exit(pcie->phy); in iproc_pcie_setup()
1545 pci_stop_root_bus(host->bus); in iproc_pcie_remove()
1546 pci_remove_root_bus(host->bus); in iproc_pcie_remove()
1550 phy_power_off(pcie->phy); in iproc_pcie_remove()
1551 phy_exit(pcie->phy); in iproc_pcie_remove()
1558 * The MSI parsing logic in certain revisions of Broadcom PAXC based root
1563 struct iproc_pcie *pcie = iproc_data(pdev->bus); in quirk_paxc_disable_msi_parsing()
1565 if (pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE) in quirk_paxc_disable_msi_parsing()
1582 if (pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE) in quirk_paxc_bridge()
1583 pdev->class = PCI_CLASS_BRIDGE_PCI_NORMAL; in quirk_paxc_bridge()
1591 pdev->pcie_mpss = 2; in quirk_paxc_bridge()