Lines Matching +full:msi +full:- +full:map

1 // SPDX-License-Identifier: GPL-2.0
6 * Copyright 2019-2020 NXP
15 #include <linux/irqchip/irq-msi-lib.h>
20 #include <linux/msi.h>
26 #include "pcie-mobiveil.h"
38 if ((bus->primary == to_pci_host_bridge(bus->bridge)->busnr) && (PCI_SLOT(devfn) > 0)) in mobiveil_pcie_valid_device()
45 * mobiveil_pcie_map_bus - routine to get the configuration base of either
51 struct mobiveil_pcie *pcie = bus->sysdata; in mobiveil_pcie_map_bus()
52 struct mobiveil_root_port *rp = &pcie->rp; in mobiveil_pcie_map_bus()
60 return pcie->csr_axi_slave_base + where; in mobiveil_pcie_map_bus()
68 value = bus->number << PAB_BUS_SHIFT | in mobiveil_pcie_map_bus()
74 return rp->config_axi_slave_base + where; in mobiveil_pcie_map_bus()
87 struct device *dev = &pcie->pdev->dev; in mobiveil_pcie_isr()
88 struct mobiveil_root_port *rp = &pcie->rp; in mobiveil_pcie_isr()
89 struct mobiveil_msi *msi = &rp->msi; in mobiveil_pcie_isr() local
96 * The core provides a single interrupt for both INTx/MSI messages. in mobiveil_pcie_isr()
97 * So we'll read both INTx and MSI status in mobiveil_pcie_isr()
116 ret = generic_handle_domain_irq(rp->intx_domain, in mobiveil_pcie_isr()
135 /* read extra MSI status register */ in mobiveil_pcie_isr()
136 msi_status = readl_relaxed(pcie->apb_csr_base + MSI_STATUS_OFFSET); in mobiveil_pcie_isr()
138 /* handle MSI interrupts */ in mobiveil_pcie_isr()
140 msi_data = readl_relaxed(pcie->apb_csr_base + MSI_DATA_OFFSET); in mobiveil_pcie_isr()
144 * once we pop not only the MSI data but also address in mobiveil_pcie_isr()
145 * from MSI hardware FIFO. So keeping these following in mobiveil_pcie_isr()
148 msi_addr_lo = readl_relaxed(pcie->apb_csr_base + in mobiveil_pcie_isr()
150 msi_addr_hi = readl_relaxed(pcie->apb_csr_base + in mobiveil_pcie_isr()
152 dev_dbg(dev, "MSI registers, data: %08x, addr: %08x:%08x\n", in mobiveil_pcie_isr()
155 generic_handle_domain_irq(msi->dev_domain, msi_data); in mobiveil_pcie_isr()
157 msi_status = readl_relaxed(pcie->apb_csr_base + in mobiveil_pcie_isr()
168 struct device *dev = &pcie->pdev->dev; in mobiveil_pcie_parse_dt()
169 struct platform_device *pdev = pcie->pdev; in mobiveil_pcie_parse_dt()
170 struct device_node *node = dev->of_node; in mobiveil_pcie_parse_dt()
171 struct mobiveil_root_port *rp = &pcie->rp; in mobiveil_pcie_parse_dt()
174 /* map config resource */ in mobiveil_pcie_parse_dt()
177 rp->config_axi_slave_base = devm_pci_remap_cfg_resource(dev, res); in mobiveil_pcie_parse_dt()
178 if (IS_ERR(rp->config_axi_slave_base)) in mobiveil_pcie_parse_dt()
179 return PTR_ERR(rp->config_axi_slave_base); in mobiveil_pcie_parse_dt()
180 rp->ob_io_res = res; in mobiveil_pcie_parse_dt()
182 /* map csr resource */ in mobiveil_pcie_parse_dt()
185 pcie->csr_axi_slave_base = devm_pci_remap_cfg_resource(dev, res); in mobiveil_pcie_parse_dt()
186 if (IS_ERR(pcie->csr_axi_slave_base)) in mobiveil_pcie_parse_dt()
187 return PTR_ERR(pcie->csr_axi_slave_base); in mobiveil_pcie_parse_dt()
188 pcie->pcie_reg_base = res->start; in mobiveil_pcie_parse_dt()
191 if (of_property_read_u32(node, "apio-wins", &pcie->apio_wins)) in mobiveil_pcie_parse_dt()
192 pcie->apio_wins = MAX_PIO_WINDOWS; in mobiveil_pcie_parse_dt()
194 if (of_property_read_u32(node, "ppio-wins", &pcie->ppio_wins)) in mobiveil_pcie_parse_dt()
195 pcie->ppio_wins = MAX_PIO_WINDOWS; in mobiveil_pcie_parse_dt()
202 phys_addr_t msg_addr = pcie->pcie_reg_base; in mobiveil_pcie_enable_msi()
203 struct mobiveil_msi *msi = &pcie->rp.msi; in mobiveil_pcie_enable_msi() local
205 msi->num_of_vectors = PCI_NUM_MSI; in mobiveil_pcie_enable_msi()
206 msi->msi_pages_phys = (phys_addr_t)msg_addr; in mobiveil_pcie_enable_msi()
209 pcie->apb_csr_base + MSI_BASE_LO_OFFSET); in mobiveil_pcie_enable_msi()
211 pcie->apb_csr_base + MSI_BASE_HI_OFFSET); in mobiveil_pcie_enable_msi()
212 writel_relaxed(4096, pcie->apb_csr_base + MSI_SIZE_OFFSET); in mobiveil_pcie_enable_msi()
213 writel_relaxed(1, pcie->apb_csr_base + MSI_ENABLE_OFFSET); in mobiveil_pcie_enable_msi()
218 struct mobiveil_root_port *rp = &pcie->rp; in mobiveil_host_init()
219 struct pci_host_bridge *bridge = rp->bridge; in mobiveil_host_init()
223 pcie->ib_wins_configured = 0; in mobiveil_host_init()
224 pcie->ob_wins_configured = 0; in mobiveil_host_init()
271 program_ob_windows(pcie, WIN_NUM_0, rp->ob_io_res->start, 0, in mobiveil_host_init()
272 CFG_WINDOW_TYPE, resource_size(rp->ob_io_res)); in mobiveil_host_init()
278 resource_list_for_each_entry(win, &bridge->windows) { in mobiveil_host_init()
279 if (resource_type(win->res) == IORESOURCE_MEM) in mobiveil_host_init()
281 else if (resource_type(win->res) == IORESOURCE_IO) in mobiveil_host_init()
287 program_ob_windows(pcie, pcie->ob_wins_configured, in mobiveil_host_init()
288 win->res->start, in mobiveil_host_init()
289 win->res->start - win->offset, in mobiveil_host_init()
290 type, resource_size(win->res)); in mobiveil_host_init()
309 rp = &pcie->rp; in mobiveil_mask_intx_irq()
310 mask = 1 << ((data->hwirq + PAB_INTX_START) - 1); in mobiveil_mask_intx_irq()
311 raw_spin_lock_irqsave(&rp->intx_mask_lock, flags); in mobiveil_mask_intx_irq()
315 raw_spin_unlock_irqrestore(&rp->intx_mask_lock, flags); in mobiveil_mask_intx_irq()
325 rp = &pcie->rp; in mobiveil_unmask_intx_irq()
326 mask = 1 << ((data->hwirq + PAB_INTX_START) - 1); in mobiveil_unmask_intx_irq()
327 raw_spin_lock_irqsave(&rp->intx_mask_lock, flags); in mobiveil_unmask_intx_irq()
331 raw_spin_unlock_irqrestore(&rp->intx_mask_lock, flags); in mobiveil_unmask_intx_irq()
347 irq_set_chip_data(irq, domain->host_data); in mobiveil_pcie_intx_map()
354 .map = mobiveil_pcie_intx_map,
368 .prefix = "Mobiveil-",
375 phys_addr_t addr = pcie->pcie_reg_base + (data->hwirq * sizeof(int)); in mobiveil_compose_msi_msg()
377 msg->address_lo = lower_32_bits(addr); in mobiveil_compose_msi_msg()
378 msg->address_hi = upper_32_bits(addr); in mobiveil_compose_msi_msg()
379 msg->data = data->hwirq; in mobiveil_compose_msi_msg()
381 dev_dbg(&pcie->pdev->dev, "msi#%d address_hi %#x address_lo %#x\n", in mobiveil_compose_msi_msg()
382 (int)data->hwirq, msg->address_hi, msg->address_lo); in mobiveil_compose_msi_msg()
386 .name = "Mobiveil MSI",
394 struct mobiveil_pcie *pcie = domain->host_data; in mobiveil_irq_msi_domain_alloc()
395 struct mobiveil_msi *msi = &pcie->rp.msi; in mobiveil_irq_msi_domain_alloc() local
399 mutex_lock(&msi->lock); in mobiveil_irq_msi_domain_alloc()
401 bit = find_first_zero_bit(msi->msi_irq_in_use, msi->num_of_vectors); in mobiveil_irq_msi_domain_alloc()
402 if (bit >= msi->num_of_vectors) { in mobiveil_irq_msi_domain_alloc()
403 mutex_unlock(&msi->lock); in mobiveil_irq_msi_domain_alloc()
404 return -ENOSPC; in mobiveil_irq_msi_domain_alloc()
407 set_bit(bit, msi->msi_irq_in_use); in mobiveil_irq_msi_domain_alloc()
409 mutex_unlock(&msi->lock); in mobiveil_irq_msi_domain_alloc()
412 domain->host_data, handle_level_irq, NULL, NULL); in mobiveil_irq_msi_domain_alloc()
422 struct mobiveil_msi *msi = &pcie->rp.msi; in mobiveil_irq_msi_domain_free() local
424 mutex_lock(&msi->lock); in mobiveil_irq_msi_domain_free()
426 if (!test_bit(d->hwirq, msi->msi_irq_in_use)) in mobiveil_irq_msi_domain_free()
427 dev_err(&pcie->pdev->dev, "trying to free unused MSI#%lu\n", in mobiveil_irq_msi_domain_free()
428 d->hwirq); in mobiveil_irq_msi_domain_free()
430 __clear_bit(d->hwirq, msi->msi_irq_in_use); in mobiveil_irq_msi_domain_free()
432 mutex_unlock(&msi->lock); in mobiveil_irq_msi_domain_free()
441 struct device *dev = &pcie->pdev->dev; in mobiveil_allocate_msi_domains()
442 struct mobiveil_msi *msi = &pcie->rp.msi; in mobiveil_allocate_msi_domains() local
444 mutex_init(&msi->lock); in mobiveil_allocate_msi_domains()
450 .size = msi->num_of_vectors, in mobiveil_allocate_msi_domains()
453 msi->dev_domain = msi_create_parent_irq_domain(&info, &mobiveil_msi_parent_ops); in mobiveil_allocate_msi_domains()
454 if (!msi->dev_domain) { in mobiveil_allocate_msi_domains()
455 dev_err(dev, "failed to create MSI domain\n"); in mobiveil_allocate_msi_domains()
456 return -ENOMEM; in mobiveil_allocate_msi_domains()
464 struct device *dev = &pcie->pdev->dev; in mobiveil_pcie_init_irq_domain()
465 struct mobiveil_root_port *rp = &pcie->rp; in mobiveil_pcie_init_irq_domain()
468 rp->intx_domain = irq_domain_create_linear(dev_fwnode(dev), PCI_NUM_INTX, &intx_domain_ops, in mobiveil_pcie_init_irq_domain()
470 if (!rp->intx_domain) { in mobiveil_pcie_init_irq_domain()
472 return -ENOMEM; in mobiveil_pcie_init_irq_domain()
475 raw_spin_lock_init(&rp->intx_mask_lock); in mobiveil_pcie_init_irq_domain()
477 /* setup MSI */ in mobiveil_pcie_init_irq_domain()
483 struct platform_device *pdev = pcie->pdev; in mobiveil_pcie_integrated_interrupt_init()
484 struct device *dev = &pdev->dev; in mobiveil_pcie_integrated_interrupt_init()
485 struct mobiveil_root_port *rp = &pcie->rp; in mobiveil_pcie_integrated_interrupt_init()
489 /* map MSI config resource */ in mobiveil_pcie_integrated_interrupt_init()
491 pcie->apb_csr_base = devm_pci_remap_cfg_resource(dev, res); in mobiveil_pcie_integrated_interrupt_init()
492 if (IS_ERR(pcie->apb_csr_base)) in mobiveil_pcie_integrated_interrupt_init()
493 return PTR_ERR(pcie->apb_csr_base); in mobiveil_pcie_integrated_interrupt_init()
495 /* setup MSI hardware registers */ in mobiveil_pcie_integrated_interrupt_init()
498 rp->irq = platform_get_irq(pdev, 0); in mobiveil_pcie_integrated_interrupt_init()
499 if (rp->irq < 0) in mobiveil_pcie_integrated_interrupt_init()
500 return rp->irq; in mobiveil_pcie_integrated_interrupt_init()
509 irq_set_chained_handler_and_data(rp->irq, mobiveil_pcie_isr, pcie); in mobiveil_pcie_integrated_interrupt_init()
521 struct mobiveil_root_port *rp = &pcie->rp; in mobiveil_pcie_interrupt_init()
523 if (rp->ops->interrupt_init) in mobiveil_pcie_interrupt_init()
524 return rp->ops->interrupt_init(pcie); in mobiveil_pcie_interrupt_init()
541 struct mobiveil_root_port *rp = &pcie->rp; in mobiveil_pcie_host_probe()
542 struct pci_host_bridge *bridge = rp->bridge; in mobiveil_pcie_host_probe()
543 struct device *dev = &pcie->pdev->dev; in mobiveil_pcie_host_probe()
553 return -ENODEV; in mobiveil_pcie_host_probe()
572 bridge->sysdata = pcie; in mobiveil_pcie_host_probe()
573 bridge->ops = &mobiveil_pcie_ops; in mobiveil_pcie_host_probe()
577 dev_info(dev, "link bring-up failed\n"); in mobiveil_pcie_host_probe()