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>
24 #include "pcie-iproc.h"
91 * struct iproc_pcie_ob_map - iProc PCIe outbound mapping controller-specific
138 * enum iproc_pcie_ib_map_type - iProc PCIe inbound mapping type
150 * struct iproc_pcie_ib_map - iProc PCIe inbound mapping controller-specific
159 * @imap_addr_offset: register offset between the upper and lower 32-bit
400 struct iproc_pcie *pcie = bus->sysdata; in iproc_data()
412 return pcie->reg_offsets[reg]; in iproc_pcie_reg_offset()
423 return readl(pcie->base + offset); in iproc_pcie_read_reg()
434 writel(val, pcie->base + offset); in iproc_pcie_write_reg()
440 * (typically seen during enumeration with multi-function devices) from
449 if (bus->number && pcie->has_apb_err_disable) { in iproc_pcie_apb_err_disable()
477 return (pcie->base + offset); in iproc_pcie_map_ep_cfg_reg()
499 * Note that a non-Vendor ID config register may have a value of in iproc_pcie_cfg_retry()
505 while (data == CFG_RETRY_STATUS && timeout--) { in iproc_pcie_cfg_retry()
539 pcie->fix_paxc_cap = true; in iproc_pcie_fix_cap()
543 if (pcie->fix_paxc_cap) { in iproc_pcie_fix_cap()
551 if (pcie->fix_paxc_cap) { in iproc_pcie_fix_cap()
572 unsigned int busno = bus->number; in iproc_pcie_config_read()
595 *val = (data >> (8 * (where & 3))) & ((1 << (size * 8)) - 1); in iproc_pcie_config_read()
610 if (pcie->rej_unconfig_pf && in iproc_pcie_config_read()
640 return (pcie->base + offset); in iproc_pcie_map_cfg_bus()
650 return iproc_pcie_map_cfg_bus(iproc_data(bus), bus->number, devfn, in iproc_pcie_bus_map_cfg_bus()
667 *val = (*val >> (8 * (where & 3))) & ((1 << (size * 8)) - 1); in iproc_pci_raw_config_read32()
688 mask = ~(((1 << (size * 8)) - 1) << ((where & 0x3) * 8)); in iproc_pci_raw_config_write32()
703 if (pcie->iproc_cfg_read) in iproc_pcie_config_read32()
739 if (pcie->ep_is_internal) in iproc_pcie_perst_ctrl()
767 struct device *dev = pcie->dev; in iproc_pcie_check_link()
775 if (pcie->ep_is_internal) in iproc_pcie_check_link()
781 return -ENODEV; in iproc_pcie_check_link()
788 return -EFAULT; in iproc_pcie_check_link()
834 return link_is_active ? 0 : -ENODEV; in iproc_pcie_check_link()
855 struct device *dev = pcie->dev; in iproc_pcie_ob_write()
859 * Derive the OARR/OMAP offset from the first pair (OARR0/OMAP0) based in iproc_pcie_ob_write()
868 return -EINVAL; in iproc_pcie_ob_write()
871 * Program the OARR registers. The upper 32-bit OARR register is in iproc_pcie_ob_write()
872 * always right after the lower 32-bit OARR register. in iproc_pcie_ob_write()
875 OARR_VALID, pcie->base + oarr_offset); in iproc_pcie_ob_write()
876 writel(upper_32_bits(axi_addr), pcie->base + oarr_offset + 4); in iproc_pcie_ob_write()
879 writel(lower_32_bits(pci_addr), pcie->base + omap_offset); in iproc_pcie_ob_write()
880 writel(upper_32_bits(pci_addr), pcie->base + omap_offset + 4); in iproc_pcie_ob_write()
885 readl(pcie->base + oarr_offset), in iproc_pcie_ob_write()
886 readl(pcie->base + oarr_offset + 4)); in iproc_pcie_ob_write()
888 readl(pcie->base + omap_offset), in iproc_pcie_ob_write()
889 readl(pcie->base + omap_offset + 4)); in iproc_pcie_ob_write()
899 * iproc_pcie_address = axi_address - axi_offset
903 * axi_addr -> iproc_pcie_address -> OARR -> OMAP -> pci_address
908 struct iproc_pcie_ob *ob = &pcie->ob; in iproc_pcie_setup_ob()
909 struct device *dev = pcie->dev; in iproc_pcie_setup_ob()
910 int ret = -EINVAL, window_idx, size_idx; in iproc_pcie_setup_ob()
912 if (axi_addr < ob->axi_offset) { in iproc_pcie_setup_ob()
914 &axi_addr, &ob->axi_offset); in iproc_pcie_setup_ob()
915 return -EINVAL; in iproc_pcie_setup_ob()
922 axi_addr -= ob->axi_offset; in iproc_pcie_setup_ob()
925 for (window_idx = ob->nr_windows - 1; window_idx >= 0; window_idx--) { in iproc_pcie_setup_ob()
927 &pcie->ob_map[window_idx]; in iproc_pcie_setup_ob()
941 for (size_idx = ob_map->nr_sizes - 1; size_idx >= 0; in iproc_pcie_setup_ob()
942 size_idx--) { in iproc_pcie_setup_ob()
944 ob_map->window_sizes[size_idx] * SZ_1M; in iproc_pcie_setup_ob()
971 return -EINVAL; in iproc_pcie_setup_ob()
983 size -= window_size; in iproc_pcie_setup_ob()
1002 &axi_addr, &ob->axi_offset, &pci_addr, &size); in iproc_pcie_setup_ob()
1010 struct device *dev = pcie->dev; in iproc_pcie_map_ranges()
1015 struct resource *res = window->res; in iproc_pcie_map_ranges()
1023 ret = iproc_pcie_setup_ob(pcie, res->start, in iproc_pcie_map_ranges()
1024 res->start - window->offset, in iproc_pcie_map_ranges()
1031 return -EINVAL; in iproc_pcie_map_ranges()
1041 const struct iproc_pcie_ib_map *ib_map = &pcie->ib_map[region_idx]; in iproc_pcie_ib_is_in_use()
1046 return !!(val & (BIT(ib_map->nr_sizes) - 1)); in iproc_pcie_ib_is_in_use()
1052 return !!(ib_map->type == type); in iproc_pcie_ib_check_type()
1059 struct device *dev = pcie->dev; in iproc_pcie_ib_write()
1060 const struct iproc_pcie_ib_map *ib_map = &pcie->ib_map[region_idx]; in iproc_pcie_ib_write()
1071 return -EINVAL; in iproc_pcie_ib_write()
1077 * Program the IARR registers. The upper 32-bit IARR register is in iproc_pcie_ib_write()
1078 * always right after the lower 32-bit IARR register. in iproc_pcie_ib_write()
1081 pcie->base + iarr_offset); in iproc_pcie_ib_write()
1082 writel(upper_32_bits(pci_addr), pcie->base + iarr_offset + 4); in iproc_pcie_ib_write()
1085 readl(pcie->base + iarr_offset), in iproc_pcie_ib_write()
1086 readl(pcie->base + iarr_offset + 4)); in iproc_pcie_ib_write()
1094 val = readl(pcie->base + imap_offset); in iproc_pcie_ib_write()
1096 writel(val, pcie->base + imap_offset); in iproc_pcie_ib_write()
1098 pcie->base + imap_offset + ib_map->imap_addr_offset); in iproc_pcie_ib_write()
1101 window_idx, readl(pcie->base + imap_offset), in iproc_pcie_ib_write()
1102 readl(pcie->base + imap_offset + in iproc_pcie_ib_write()
1103 ib_map->imap_addr_offset)); in iproc_pcie_ib_write()
1105 imap_offset += ib_map->imap_window_offset; in iproc_pcie_ib_write()
1116 struct device *dev = pcie->dev; in iproc_pcie_setup_ib()
1117 struct iproc_pcie_ib *ib = &pcie->ib; in iproc_pcie_setup_ib()
1120 u64 axi_addr = entry->res->start; in iproc_pcie_setup_ib()
1121 u64 pci_addr = entry->res->start - entry->offset; in iproc_pcie_setup_ib()
1122 resource_size_t size = resource_size(entry->res); in iproc_pcie_setup_ib()
1125 for (region_idx = 0; region_idx < ib->nr_regions; region_idx++) { in iproc_pcie_setup_ib()
1127 &pcie->ib_map[region_idx]; in iproc_pcie_setup_ib()
1138 for (size_idx = 0; size_idx < ib_map->nr_sizes; size_idx++) { in iproc_pcie_setup_ib()
1140 ib_map->region_sizes[size_idx] * ib_map->size_unit; in iproc_pcie_setup_ib()
1150 return -EINVAL; in iproc_pcie_setup_ib()
1155 ib_map->nr_windows, axi_addr, in iproc_pcie_setup_ib()
1164 ret = -EINVAL; in iproc_pcie_setup_ib()
1180 resource_list_for_each_entry(entry, &host->dma_ranges) { in iproc_pcie_map_dma_ranges()
1192 struct iproc_pcie_ib *ib = &pcie->ib; in iproc_pcie_invalidate_mapping()
1193 struct iproc_pcie_ob *ob = &pcie->ob; in iproc_pcie_invalidate_mapping()
1196 if (pcie->ep_is_internal) in iproc_pcie_invalidate_mapping()
1199 if (pcie->need_ob_cfg) { in iproc_pcie_invalidate_mapping()
1201 for (idx = ob->nr_windows - 1; idx >= 0; idx--) { in iproc_pcie_invalidate_mapping()
1207 if (pcie->need_ib_cfg) { in iproc_pcie_invalidate_mapping()
1209 for (idx = 0; idx < ib->nr_regions; idx++) { in iproc_pcie_invalidate_mapping()
1220 struct device *dev = pcie->dev; in iproce_pcie_get_msi()
1225 * Check if 'msi-map' points to ARM GICv3 ITS, which is the only in iproce_pcie_get_msi()
1228 if (!of_device_is_compatible(msi_node, "arm,gic-v3-its")) { in iproce_pcie_get_msi()
1230 return -ENODEV; in iproce_pcie_get_msi()
1252 msi_addr &= ~(SZ_32K - 1); in iproc_pcie_paxb_v2_msi_steer()
1253 entry.res->start = msi_addr; in iproc_pcie_paxb_v2_msi_steer()
1254 entry.res->end = msi_addr + SZ_32K - 1; in iproc_pcie_paxb_v2_msi_steer()
1268 * treated as non-MSI transfers in iproc_pcie_paxc_v2_msi_steer()
1279 * based SoCs, all I/O register bases are well below the 32-bit in iproc_pcie_paxc_v2_msi_steer()
1312 struct device *dev = pcie->dev; in iproc_pcie_msi_steer()
1322 switch (pcie->type) { in iproc_pcie_msi_steer()
1332 return -EINVAL; in iproc_pcie_msi_steer()
1344 * Either the "msi-parent" or the "msi-map" phandle needs to exist in iproc_pcie_msi_enable()
1348 msi_node = of_parse_phandle(pcie->dev->of_node, "msi-parent", 0); in iproc_pcie_msi_enable()
1354 msi_map = of_get_property(pcie->dev->of_node, "msi-map", &len); in iproc_pcie_msi_enable()
1356 return -ENODEV; in iproc_pcie_msi_enable()
1361 return -ENODEV; in iproc_pcie_msi_enable()
1369 if (pcie->need_msi_steer) { in iproc_pcie_msi_enable()
1393 struct device *dev = pcie->dev; in iproc_pcie_rev_init()
1397 switch (pcie->type) { in iproc_pcie_rev_init()
1403 pcie->has_apb_err_disable = true; in iproc_pcie_rev_init()
1404 if (pcie->need_ob_cfg) { in iproc_pcie_rev_init()
1405 pcie->ob_map = paxb_ob_map; in iproc_pcie_rev_init()
1406 pcie->ob.nr_windows = ARRAY_SIZE(paxb_ob_map); in iproc_pcie_rev_init()
1411 pcie->iproc_cfg_read = true; in iproc_pcie_rev_init()
1412 pcie->has_apb_err_disable = true; in iproc_pcie_rev_init()
1413 if (pcie->need_ob_cfg) { in iproc_pcie_rev_init()
1414 pcie->ob_map = paxb_v2_ob_map; in iproc_pcie_rev_init()
1415 pcie->ob.nr_windows = ARRAY_SIZE(paxb_v2_ob_map); in iproc_pcie_rev_init()
1417 pcie->ib.nr_regions = ARRAY_SIZE(paxb_v2_ib_map); in iproc_pcie_rev_init()
1418 pcie->ib_map = paxb_v2_ib_map; in iproc_pcie_rev_init()
1419 pcie->need_msi_steer = true; in iproc_pcie_rev_init()
1425 pcie->ep_is_internal = true; in iproc_pcie_rev_init()
1426 pcie->iproc_cfg_read = true; in iproc_pcie_rev_init()
1427 pcie->rej_unconfig_pf = true; in iproc_pcie_rev_init()
1431 pcie->ep_is_internal = true; in iproc_pcie_rev_init()
1432 pcie->iproc_cfg_read = true; in iproc_pcie_rev_init()
1433 pcie->rej_unconfig_pf = true; in iproc_pcie_rev_init()
1434 pcie->need_msi_steer = true; in iproc_pcie_rev_init()
1438 return -EINVAL; in iproc_pcie_rev_init()
1441 pcie->reg_offsets = devm_kcalloc(dev, IPROC_PCIE_MAX_NUM_REG, in iproc_pcie_rev_init()
1442 sizeof(*pcie->reg_offsets), in iproc_pcie_rev_init()
1444 if (!pcie->reg_offsets) in iproc_pcie_rev_init()
1445 return -ENOMEM; in iproc_pcie_rev_init()
1448 pcie->reg_offsets[0] = (pcie->type == IPROC_PCIE_PAXC_V2) ? in iproc_pcie_rev_init()
1451 pcie->reg_offsets[reg_idx] = regs[reg_idx] ? in iproc_pcie_rev_init()
1464 dev = pcie->dev; in iproc_pcie_setup()
1472 ret = phy_init(pcie->phy); in iproc_pcie_setup()
1478 ret = phy_power_on(pcie->phy); in iproc_pcie_setup()
1489 if (pcie->need_ob_cfg) { in iproc_pcie_setup()
1497 if (pcie->need_ib_cfg) { in iproc_pcie_setup()
1499 if (ret && ret != -ENOENT) in iproc_pcie_setup()
1515 host->ops = &iproc_pcie_ops; in iproc_pcie_setup()
1516 host->sysdata = pcie; in iproc_pcie_setup()
1517 host->map_irq = pcie->map_irq; in iproc_pcie_setup()
1525 for_each_pci_bridge(pdev, host->bus) { in iproc_pcie_setup()
1533 phy_power_off(pcie->phy); in iproc_pcie_setup()
1535 phy_exit(pcie->phy); in iproc_pcie_setup()
1544 pci_stop_root_bus(host->bus); in iproc_pcie_remove()
1545 pci_remove_root_bus(host->bus); in iproc_pcie_remove()
1549 phy_power_off(pcie->phy); in iproc_pcie_remove()
1550 phy_exit(pcie->phy); in iproc_pcie_remove()
1555 * The MSI parsing logic in certain revisions of Broadcom PAXC based root
1560 struct iproc_pcie *pcie = iproc_data(pdev->bus); in quirk_paxc_disable_msi_parsing()
1562 if (pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE) in quirk_paxc_disable_msi_parsing()
1579 if (pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE) in quirk_paxc_bridge()
1580 pdev->class = PCI_CLASS_BRIDGE_PCI_NORMAL; in quirk_paxc_bridge()
1588 pdev->pcie_mpss = 2; in quirk_paxc_bridge()