Lines Matching +full:ecam +full:- +full:based
1 // SPDX-License-Identifier: GPL-2.0+
4 * Based on pcie-xilinx.c, pci-tegra.c
6 * (C) Copyright 2014 - 2015, Xilinx, Inc.
31 /* Egress - Bridge translation registers */
41 /* Ingress - address translations */
49 /* Rxed msg fifo - Interrupt status registers */
176 return readl(pcie->breg_base + off); in nwl_bridge_readl()
181 writel(val, pcie->breg_base + off); in nwl_bridge_writel()
186 if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PCIE_PHY_LINKUP_BIT) in nwl_pcie_link_up()
193 if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PHY_RDY_LINKUP_BIT) in nwl_phy_link_up()
200 struct device *dev = pcie->dev; in nwl_wait_for_link()
211 return -ETIMEDOUT; in nwl_wait_for_link()
216 struct nwl_pcie *pcie = bus->sysdata; in nwl_pcie_valid_device()
230 * nwl_pcie_map_bus - Get configuration base
242 struct nwl_pcie *pcie = bus->sysdata; in nwl_pcie_map_bus()
248 relbus = (bus->number << ECAM_BUS_LOC_SHIFT) | in nwl_pcie_map_bus()
251 return pcie->ecam_base + relbus + where; in nwl_pcie_map_bus()
264 struct device *dev = pcie->dev; in nwl_pcie_misc_handler()
292 dev_err(dev, "Non-Fatal Error in AER Capability\n"); in nwl_pcie_misc_handler()
301 dev_err(dev, "Non-Fatal Error Detected\n"); in nwl_pcie_misc_handler()
332 virq = irq_find_mapping(pcie->legacy_irq_domain, bit); in nwl_pcie_leg_handler()
348 msi = &pcie->msi; in nwl_pcie_handle_msi_irq()
353 virq = irq_find_mapping(msi->dev_domain, bit); in nwl_pcie_handle_msi_irq()
382 struct irq_desc *desc = irq_to_desc(data->irq); in nwl_mask_leg_irq()
389 mask = 1 << (data->hwirq - 1); in nwl_mask_leg_irq()
390 raw_spin_lock_irqsave(&pcie->leg_mask_lock, flags); in nwl_mask_leg_irq()
393 raw_spin_unlock_irqrestore(&pcie->leg_mask_lock, flags); in nwl_mask_leg_irq()
398 struct irq_desc *desc = irq_to_desc(data->irq); in nwl_unmask_leg_irq()
405 mask = 1 << (data->hwirq - 1); in nwl_unmask_leg_irq()
406 raw_spin_lock_irqsave(&pcie->leg_mask_lock, flags); in nwl_unmask_leg_irq()
409 raw_spin_unlock_irqrestore(&pcie->leg_mask_lock, flags); in nwl_unmask_leg_irq()
424 irq_set_chip_data(irq, domain->host_data); in nwl_legacy_map()
454 phys_addr_t msi_addr = pcie->phys_pcie_reg_base; in nwl_compose_msi_msg()
456 msg->address_lo = lower_32_bits(msi_addr); in nwl_compose_msi_msg()
457 msg->address_hi = upper_32_bits(msi_addr); in nwl_compose_msi_msg()
458 msg->data = data->hwirq; in nwl_compose_msi_msg()
464 return -EINVAL; in nwl_msi_set_affinity()
476 struct nwl_pcie *pcie = domain->host_data; in nwl_irq_domain_alloc()
477 struct nwl_msi *msi = &pcie->msi; in nwl_irq_domain_alloc()
481 mutex_lock(&msi->lock); in nwl_irq_domain_alloc()
482 bit = bitmap_find_free_region(msi->bitmap, INT_PCI_MSI_NR, in nwl_irq_domain_alloc()
485 mutex_unlock(&msi->lock); in nwl_irq_domain_alloc()
486 return -ENOSPC; in nwl_irq_domain_alloc()
491 domain->host_data, handle_simple_irq, in nwl_irq_domain_alloc()
494 mutex_unlock(&msi->lock); in nwl_irq_domain_alloc()
503 struct nwl_msi *msi = &pcie->msi; in nwl_irq_domain_free()
505 mutex_lock(&msi->lock); in nwl_irq_domain_free()
506 bitmap_release_region(msi->bitmap, data->hwirq, in nwl_irq_domain_free()
508 mutex_unlock(&msi->lock); in nwl_irq_domain_free()
519 struct device *dev = pcie->dev; in nwl_pcie_init_msi_irq_domain()
520 struct fwnode_handle *fwnode = of_node_to_fwnode(dev->of_node); in nwl_pcie_init_msi_irq_domain()
521 struct nwl_msi *msi = &pcie->msi; in nwl_pcie_init_msi_irq_domain()
523 msi->dev_domain = irq_domain_add_linear(NULL, INT_PCI_MSI_NR, in nwl_pcie_init_msi_irq_domain()
525 if (!msi->dev_domain) { in nwl_pcie_init_msi_irq_domain()
527 return -ENOMEM; in nwl_pcie_init_msi_irq_domain()
529 msi->msi_domain = pci_msi_create_irq_domain(fwnode, in nwl_pcie_init_msi_irq_domain()
531 msi->dev_domain); in nwl_pcie_init_msi_irq_domain()
532 if (!msi->msi_domain) { in nwl_pcie_init_msi_irq_domain()
534 irq_domain_remove(msi->dev_domain); in nwl_pcie_init_msi_irq_domain()
535 return -ENOMEM; in nwl_pcie_init_msi_irq_domain()
543 struct device *dev = pcie->dev; in nwl_pcie_init_irq_domain()
544 struct device_node *node = dev->of_node; in nwl_pcie_init_irq_domain()
550 return -EINVAL; in nwl_pcie_init_irq_domain()
553 pcie->legacy_irq_domain = irq_domain_add_linear(legacy_intc_node, in nwl_pcie_init_irq_domain()
558 if (!pcie->legacy_irq_domain) { in nwl_pcie_init_irq_domain()
560 return -ENOMEM; in nwl_pcie_init_irq_domain()
563 raw_spin_lock_init(&pcie->leg_mask_lock); in nwl_pcie_init_irq_domain()
570 struct device *dev = pcie->dev; in nwl_pcie_enable_msi()
572 struct nwl_msi *msi = &pcie->msi; in nwl_pcie_enable_msi()
577 mutex_init(&msi->lock); in nwl_pcie_enable_msi()
579 msi->bitmap = kzalloc(size, GFP_KERNEL); in nwl_pcie_enable_msi()
580 if (!msi->bitmap) in nwl_pcie_enable_msi()
581 return -ENOMEM; in nwl_pcie_enable_msi()
584 msi->irq_msi1 = platform_get_irq_byname(pdev, "msi1"); in nwl_pcie_enable_msi()
585 if (msi->irq_msi1 < 0) { in nwl_pcie_enable_msi()
586 ret = -EINVAL; in nwl_pcie_enable_msi()
590 irq_set_chained_handler_and_data(msi->irq_msi1, in nwl_pcie_enable_msi()
594 msi->irq_msi0 = platform_get_irq_byname(pdev, "msi0"); in nwl_pcie_enable_msi()
595 if (msi->irq_msi0 < 0) { in nwl_pcie_enable_msi()
596 ret = -EINVAL; in nwl_pcie_enable_msi()
600 irq_set_chained_handler_and_data(msi->irq_msi0, in nwl_pcie_enable_msi()
607 ret = -EIO; in nwl_pcie_enable_msi()
620 base = pcie->phys_pcie_reg_base; in nwl_pcie_enable_msi()
648 kfree(msi->bitmap); in nwl_pcie_enable_msi()
649 msi->bitmap = NULL; in nwl_pcie_enable_msi()
655 struct device *dev = pcie->dev; in nwl_pcie_bridge_init()
667 nwl_bridge_writel(pcie, lower_32_bits(pcie->phys_breg_base), in nwl_pcie_bridge_init()
669 nwl_bridge_writel(pcie, upper_32_bits(pcie->phys_breg_base), in nwl_pcie_bridge_init()
693 dev_err(dev, "ECAM is not present\n"); in nwl_pcie_bridge_init()
697 /* Enable ECAM */ in nwl_pcie_bridge_init()
702 (pcie->ecam_value << E_ECAM_SIZE_SHIFT), in nwl_pcie_bridge_init()
705 nwl_bridge_writel(pcie, lower_32_bits(pcie->phys_ecam_base), in nwl_pcie_bridge_init()
707 nwl_bridge_writel(pcie, upper_32_bits(pcie->phys_ecam_base), in nwl_pcie_bridge_init()
712 pcie->last_busno = (ecam_val & E_ECAM_SIZE_LOC) >> E_ECAM_SIZE_SHIFT; in nwl_pcie_bridge_init()
716 ecam_val |= (pcie->last_busno << E_ECAM_SIZE_SHIFT); in nwl_pcie_bridge_init()
717 writel(ecam_val, (pcie->ecam_base + PCI_PRIMARY_BUS)); in nwl_pcie_bridge_init()
725 pcie->irq_misc = platform_get_irq_byname(pdev, "misc"); in nwl_pcie_bridge_init()
726 if (pcie->irq_misc < 0) in nwl_pcie_bridge_init()
727 return -EINVAL; in nwl_pcie_bridge_init()
729 err = devm_request_irq(dev, pcie->irq_misc, in nwl_pcie_bridge_init()
734 pcie->irq_misc); in nwl_pcie_bridge_init()
769 struct device *dev = pcie->dev; in nwl_pcie_parse_dt()
773 pcie->breg_base = devm_ioremap_resource(dev, res); in nwl_pcie_parse_dt()
774 if (IS_ERR(pcie->breg_base)) in nwl_pcie_parse_dt()
775 return PTR_ERR(pcie->breg_base); in nwl_pcie_parse_dt()
776 pcie->phys_breg_base = res->start; in nwl_pcie_parse_dt()
779 pcie->pcireg_base = devm_ioremap_resource(dev, res); in nwl_pcie_parse_dt()
780 if (IS_ERR(pcie->pcireg_base)) in nwl_pcie_parse_dt()
781 return PTR_ERR(pcie->pcireg_base); in nwl_pcie_parse_dt()
782 pcie->phys_pcie_reg_base = res->start; in nwl_pcie_parse_dt()
785 pcie->ecam_base = devm_pci_remap_cfg_resource(dev, res); in nwl_pcie_parse_dt()
786 if (IS_ERR(pcie->ecam_base)) in nwl_pcie_parse_dt()
787 return PTR_ERR(pcie->ecam_base); in nwl_pcie_parse_dt()
788 pcie->phys_ecam_base = res->start; in nwl_pcie_parse_dt()
791 pcie->irq_intx = platform_get_irq_byname(pdev, "intx"); in nwl_pcie_parse_dt()
792 if (pcie->irq_intx < 0) in nwl_pcie_parse_dt()
793 return pcie->irq_intx; in nwl_pcie_parse_dt()
795 irq_set_chained_handler_and_data(pcie->irq_intx, in nwl_pcie_parse_dt()
802 { .compatible = "xlnx,nwl-pcie-2.11", },
808 struct device *dev = &pdev->dev; in nwl_pcie_probe()
815 return -ENODEV; in nwl_pcie_probe()
819 pcie->dev = dev; in nwl_pcie_probe()
820 pcie->ecam_value = NWL_ECAM_VALUE_DEFAULT; in nwl_pcie_probe()
840 bridge->sysdata = pcie; in nwl_pcie_probe()
841 bridge->ops = &nwl_pcie_ops; in nwl_pcie_probe()
856 .name = "nwl-pcie",