Lines Matching +full:msi +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0
13 #include <linux/msi.h>
15 #include <linux/pci-ecam.h>
17 #include "pcie-plda.h"
22 struct plda_pcie_rp *pcie = bus->sysdata; in plda_pcie_map_bus()
24 return pcie->config_base + PCIE_ECAM_OFFSET(bus->number, devfn, where); in plda_pcie_map_bus()
32 struct device *dev = port->dev; in plda_handle_msi()
33 struct plda_msi *msi = &port->msi; in plda_handle_msi() local
34 void __iomem *bridge_base_addr = port->bridge_addr; in plda_handle_msi()
46 for_each_set_bit(bit, &status, msi->num_vectors) { in plda_handle_msi()
47 ret = generic_handle_domain_irq(msi->dev_domain, bit); in plda_handle_msi()
49 dev_err_ratelimited(dev, "bad MSI IRQ %d\n", in plda_handle_msi()
60 void __iomem *bridge_base_addr = port->bridge_addr; in plda_msi_bottom_irq_ack()
61 u32 bitpos = data->hwirq; in plda_msi_bottom_irq_ack()
69 phys_addr_t addr = port->msi.vector_phy; in plda_compose_msi_msg()
71 msg->address_lo = lower_32_bits(addr); in plda_compose_msi_msg()
72 msg->address_hi = upper_32_bits(addr); in plda_compose_msi_msg()
73 msg->data = data->hwirq; in plda_compose_msi_msg()
75 dev_dbg(port->dev, "msi#%x address_hi %#x address_lo %#x\n", in plda_compose_msi_msg()
76 (int)data->hwirq, msg->address_hi, msg->address_lo); in plda_compose_msi_msg()
80 .name = "PLDA MSI",
90 struct plda_pcie_rp *port = domain->host_data; in plda_irq_msi_domain_alloc()
91 struct plda_msi *msi = &port->msi; in plda_irq_msi_domain_alloc() local
94 mutex_lock(&msi->lock); in plda_irq_msi_domain_alloc()
95 bit = find_first_zero_bit(msi->used, msi->num_vectors); in plda_irq_msi_domain_alloc()
96 if (bit >= msi->num_vectors) { in plda_irq_msi_domain_alloc()
97 mutex_unlock(&msi->lock); in plda_irq_msi_domain_alloc()
98 return -ENOSPC; in plda_irq_msi_domain_alloc()
101 set_bit(bit, msi->used); in plda_irq_msi_domain_alloc()
104 domain->host_data, handle_edge_irq, NULL, NULL); in plda_irq_msi_domain_alloc()
106 mutex_unlock(&msi->lock); in plda_irq_msi_domain_alloc()
117 struct plda_msi *msi = &port->msi; in plda_irq_msi_domain_free() local
119 mutex_lock(&msi->lock); in plda_irq_msi_domain_free()
121 if (test_bit(d->hwirq, msi->used)) in plda_irq_msi_domain_free()
122 __clear_bit(d->hwirq, msi->used); in plda_irq_msi_domain_free()
124 dev_err(port->dev, "trying to free unused MSI%lu\n", d->hwirq); in plda_irq_msi_domain_free()
126 mutex_unlock(&msi->lock); in plda_irq_msi_domain_free()
135 .name = "PLDA PCIe MSI",
149 struct device *dev = port->dev; in plda_allocate_msi_domains()
150 struct fwnode_handle *fwnode = of_node_to_fwnode(dev->of_node); in plda_allocate_msi_domains()
151 struct plda_msi *msi = &port->msi; in plda_allocate_msi_domains() local
153 mutex_init(&port->msi.lock); in plda_allocate_msi_domains()
155 msi->dev_domain = irq_domain_add_linear(NULL, msi->num_vectors, in plda_allocate_msi_domains()
157 if (!msi->dev_domain) { in plda_allocate_msi_domains()
159 return -ENOMEM; in plda_allocate_msi_domains()
162 msi->msi_domain = pci_msi_create_irq_domain(fwnode, in plda_allocate_msi_domains()
164 msi->dev_domain); in plda_allocate_msi_domains()
165 if (!msi->msi_domain) { in plda_allocate_msi_domains()
166 dev_err(dev, "failed to create MSI domain\n"); in plda_allocate_msi_domains()
167 irq_domain_remove(msi->dev_domain); in plda_allocate_msi_domains()
168 return -ENOMEM; in plda_allocate_msi_domains()
178 struct device *dev = port->dev; in plda_handle_intx()
179 void __iomem *bridge_base_addr = port->bridge_addr; in plda_handle_intx()
191 ret = generic_handle_domain_irq(port->intx_domain, bit); in plda_handle_intx()
204 void __iomem *bridge_base_addr = port->bridge_addr; in plda_ack_intx_irq()
205 u32 mask = BIT(data->hwirq + PM_MSI_INT_INTX_SHIFT); in plda_ack_intx_irq()
213 void __iomem *bridge_base_addr = port->bridge_addr; in plda_mask_intx_irq()
215 u32 mask = BIT(data->hwirq + PM_MSI_INT_INTX_SHIFT); in plda_mask_intx_irq()
218 raw_spin_lock_irqsave(&port->lock, flags); in plda_mask_intx_irq()
222 raw_spin_unlock_irqrestore(&port->lock, flags); in plda_mask_intx_irq()
228 void __iomem *bridge_base_addr = port->bridge_addr; in plda_unmask_intx_irq()
230 u32 mask = BIT(data->hwirq + PM_MSI_INT_INTX_SHIFT); in plda_unmask_intx_irq()
233 raw_spin_lock_irqsave(&port->lock, flags); in plda_unmask_intx_irq()
237 raw_spin_unlock_irqrestore(&port->lock, flags); in plda_unmask_intx_irq()
251 irq_set_chip_data(irq, domain->host_data); in plda_pcie_intx_map()
264 origin = readl_relaxed(port->bridge_addr + ISTATUS_LOCAL); in plda_get_events()
266 /* MSI event and sys events */ in plda_get_events()
268 events = val << (PM_MSI_INT_MSI_SHIFT - PCI_NUM_INTX + 1); in plda_get_events()
294 events = port->event_ops->get_events(port); in plda_handle_event()
296 events &= port->events_bitmap; in plda_handle_event()
297 for_each_set_bit(bit, &events, port->num_events) in plda_handle_event()
298 generic_handle_domain_irq(port->event_domain, bit); in plda_handle_event()
307 /* hwirq 23 - 0 are the same with register */ in plda_hwirq_to_mask()
313 mask = BIT(hwirq + PCI_NUM_INTX - 1); in plda_hwirq_to_mask()
322 writel_relaxed(plda_hwirq_to_mask(data->hwirq), in plda_ack_event_irq()
323 port->bridge_addr + ISTATUS_LOCAL); in plda_ack_event_irq()
331 mask = plda_hwirq_to_mask(data->hwirq); in plda_mask_event_irq()
333 raw_spin_lock(&port->lock); in plda_mask_event_irq()
334 val = readl_relaxed(port->bridge_addr + IMASK_LOCAL); in plda_mask_event_irq()
336 writel_relaxed(val, port->bridge_addr + IMASK_LOCAL); in plda_mask_event_irq()
337 raw_spin_unlock(&port->lock); in plda_mask_event_irq()
345 mask = plda_hwirq_to_mask(data->hwirq); in plda_unmask_event_irq()
347 raw_spin_lock(&port->lock); in plda_unmask_event_irq()
348 val = readl_relaxed(port->bridge_addr + IMASK_LOCAL); in plda_unmask_event_irq()
350 writel_relaxed(val, port->bridge_addr + IMASK_LOCAL); in plda_unmask_event_irq()
351 raw_spin_unlock(&port->lock); in plda_unmask_event_irq()
368 struct plda_pcie_rp *port = (void *)domain->host_data; in plda_pcie_event_map()
370 irq_set_chip_and_handler(irq, port->event_irq_chip, handle_level_irq); in plda_pcie_event_map()
371 irq_set_chip_data(irq, domain->host_data); in plda_pcie_event_map()
382 struct device *dev = port->dev; in plda_pcie_init_irq_domains()
383 struct device_node *node = dev->of_node; in plda_pcie_init_irq_domains()
390 return -EINVAL; in plda_pcie_init_irq_domains()
393 port->event_domain = irq_domain_add_linear(pcie_intc_node, in plda_pcie_init_irq_domains()
394 port->num_events, in plda_pcie_init_irq_domains()
397 if (!port->event_domain) { in plda_pcie_init_irq_domains()
400 return -ENOMEM; in plda_pcie_init_irq_domains()
403 irq_domain_update_bus_token(port->event_domain, DOMAIN_BUS_NEXUS); in plda_pcie_init_irq_domains()
405 port->intx_domain = irq_domain_add_linear(pcie_intc_node, PCI_NUM_INTX, in plda_pcie_init_irq_domains()
407 if (!port->intx_domain) { in plda_pcie_init_irq_domains()
410 return -ENOMEM; in plda_pcie_init_irq_domains()
413 irq_domain_update_bus_token(port->intx_domain, DOMAIN_BUS_WIRED); in plda_pcie_init_irq_domains()
416 raw_spin_lock_init(&port->lock); in plda_pcie_init_irq_domains()
425 struct device *dev = &pdev->dev; in plda_init_interrupts()
429 if (!port->event_ops) in plda_init_interrupts()
430 port->event_ops = &plda_event_ops; in plda_init_interrupts()
432 if (!port->event_irq_chip) in plda_init_interrupts()
433 port->event_irq_chip = &plda_event_irq_chip; in plda_init_interrupts()
441 port->irq = platform_get_irq(pdev, 0); in plda_init_interrupts()
442 if (port->irq < 0) in plda_init_interrupts()
443 return -ENODEV; in plda_init_interrupts()
445 for_each_set_bit(i, &port->events_bitmap, port->num_events) { in plda_init_interrupts()
446 event_irq = irq_create_mapping(port->event_domain, i); in plda_init_interrupts()
449 return -ENXIO; in plda_init_interrupts()
452 if (event->request_event_irq) in plda_init_interrupts()
453 ret = event->request_event_irq(port, event_irq, i); in plda_init_interrupts()
465 port->intx_irq = irq_create_mapping(port->event_domain, in plda_init_interrupts()
466 event->intx_event); in plda_init_interrupts()
467 if (!port->intx_irq) { in plda_init_interrupts()
469 return -ENXIO; in plda_init_interrupts()
473 irq_set_chained_handler_and_data(port->intx_irq, plda_handle_intx, port); in plda_init_interrupts()
475 port->msi_irq = irq_create_mapping(port->event_domain, in plda_init_interrupts()
476 event->msi_event); in plda_init_interrupts()
477 if (!port->msi_irq) in plda_init_interrupts()
478 return -ENXIO; in plda_init_interrupts()
480 /* Plug the MSI chained handler */ in plda_init_interrupts()
481 irq_set_chained_handler_and_data(port->msi_irq, plda_handle_msi, port); in plda_init_interrupts()
484 irq_set_chained_handler_and_data(port->irq, plda_handle_event, port); in plda_init_interrupts()
494 u32 atr_sz = ilog2(size) - 1; in plda_pcie_setup_window()
532 void __iomem *bridge_base_addr = port->bridge_addr; in plda_pcie_setup_iomems()
535 u32 index = 1; in plda_pcie_setup_iomems()
537 resource_list_for_each_entry(entry, &bridge->windows) { in plda_pcie_setup_iomems()
538 if (resource_type(entry->res) == IORESOURCE_MEM) { in plda_pcie_setup_iomems()
539 pci_addr = entry->res->start - entry->offset; in plda_pcie_setup_iomems()
541 entry->res->start, pci_addr, in plda_pcie_setup_iomems()
542 resource_size(entry->res)); in plda_pcie_setup_iomems()
553 irq_set_chained_handler_and_data(pcie->irq, NULL, NULL); in plda_pcie_irq_domain_deinit()
554 irq_set_chained_handler_and_data(pcie->msi_irq, NULL, NULL); in plda_pcie_irq_domain_deinit()
555 irq_set_chained_handler_and_data(pcie->intx_irq, NULL, NULL); in plda_pcie_irq_domain_deinit()
557 irq_domain_remove(pcie->msi.msi_domain); in plda_pcie_irq_domain_deinit()
558 irq_domain_remove(pcie->msi.dev_domain); in plda_pcie_irq_domain_deinit()
560 irq_domain_remove(pcie->intx_domain); in plda_pcie_irq_domain_deinit()
561 irq_domain_remove(pcie->event_domain); in plda_pcie_irq_domain_deinit()
567 struct device *dev = port->dev; in plda_pcie_host_init()
575 port->bridge_addr = in plda_pcie_host_init()
578 if (IS_ERR(port->bridge_addr)) in plda_pcie_host_init()
579 return dev_err_probe(dev, PTR_ERR(port->bridge_addr), in plda_pcie_host_init()
584 return dev_err_probe(dev, -ENODEV, in plda_pcie_host_init()
587 port->config_base = devm_ioremap_resource(dev, cfg_res); in plda_pcie_host_init()
588 if (IS_ERR(port->config_base)) in plda_pcie_host_init()
589 return dev_err_probe(dev, PTR_ERR(port->config_base), in plda_pcie_host_init()
594 return dev_err_probe(dev, -ENOMEM, in plda_pcie_host_init()
597 if (port->host_ops && port->host_ops->host_init) { in plda_pcie_host_init()
598 ret = port->host_ops->host_init(port); in plda_pcie_host_init()
603 port->bridge = bridge; in plda_pcie_host_init()
604 plda_pcie_setup_window(port->bridge_addr, 0, cfg_res->start, 0, in plda_pcie_host_init()
607 plda_set_default_msi(&port->msi); in plda_pcie_host_init()
613 bridge->ops = ops; in plda_pcie_host_init()
614 bridge->sysdata = port; in plda_pcie_host_init()
627 if (port->host_ops && port->host_ops->host_deinit) in plda_pcie_host_init()
628 port->host_ops->host_deinit(port); in plda_pcie_host_init()
636 pci_stop_root_bus(port->bridge->bus); in plda_pcie_host_deinit()
637 pci_remove_root_bus(port->bridge->bus); in plda_pcie_host_deinit()
641 if (port->host_ops && port->host_ops->host_deinit) in plda_pcie_host_deinit()
642 port->host_ops->host_deinit(port); in plda_pcie_host_deinit()