• Home
  • Raw
  • Download

Lines Matching +full:pci +full:- +full:domain

1 // SPDX-License-Identifier: GPL-2.0
19 #include "../../pci.h"
20 #include "pcie-designware.h"
43 .name = "PCI-MSI",
62 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_handle_msi_irq() local
64 num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL; in dw_handle_msi_irq()
67 status = dw_pcie_readl_dbi(pci, PCIE_MSI_INTR0_STATUS + in dw_handle_msi_irq()
77 irq = irq_find_mapping(pp->irq_domain, in dw_handle_msi_irq()
105 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pci_setup_msi_msg() local
108 msi_target = (u64)pp->msi_data; in dw_pci_setup_msi_msg()
110 msg->address_lo = lower_32_bits(msi_target); in dw_pci_setup_msi_msg()
111 msg->address_hi = upper_32_bits(msi_target); in dw_pci_setup_msi_msg()
113 msg->data = d->hwirq; in dw_pci_setup_msi_msg()
115 dev_dbg(pci->dev, "msi#%d address_hi %#x address_lo %#x\n", in dw_pci_setup_msi_msg()
116 (int)d->hwirq, msg->address_hi, msg->address_lo); in dw_pci_setup_msi_msg()
122 return -EINVAL; in dw_pci_msi_set_affinity()
128 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pci_bottom_mask() local
132 raw_spin_lock_irqsave(&pp->lock, flags); in dw_pci_bottom_mask()
134 ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL; in dw_pci_bottom_mask()
136 bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL; in dw_pci_bottom_mask()
138 pp->irq_mask[ctrl] |= BIT(bit); in dw_pci_bottom_mask()
139 dw_pcie_writel_dbi(pci, PCIE_MSI_INTR0_MASK + res, pp->irq_mask[ctrl]); in dw_pci_bottom_mask()
141 raw_spin_unlock_irqrestore(&pp->lock, flags); in dw_pci_bottom_mask()
147 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pci_bottom_unmask() local
151 raw_spin_lock_irqsave(&pp->lock, flags); in dw_pci_bottom_unmask()
153 ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL; in dw_pci_bottom_unmask()
155 bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL; in dw_pci_bottom_unmask()
157 pp->irq_mask[ctrl] &= ~BIT(bit); in dw_pci_bottom_unmask()
158 dw_pcie_writel_dbi(pci, PCIE_MSI_INTR0_MASK + res, pp->irq_mask[ctrl]); in dw_pci_bottom_unmask()
160 raw_spin_unlock_irqrestore(&pp->lock, flags); in dw_pci_bottom_unmask()
166 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pci_bottom_ack() local
169 ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL; in dw_pci_bottom_ack()
171 bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL; in dw_pci_bottom_ack()
173 dw_pcie_writel_dbi(pci, PCIE_MSI_INTR0_STATUS + res, BIT(bit)); in dw_pci_bottom_ack()
177 .name = "DWPCI-MSI",
185 static int dw_pcie_irq_domain_alloc(struct irq_domain *domain, in dw_pcie_irq_domain_alloc() argument
189 struct pcie_port *pp = domain->host_data; in dw_pcie_irq_domain_alloc()
194 raw_spin_lock_irqsave(&pp->lock, flags); in dw_pcie_irq_domain_alloc()
196 bit = bitmap_find_free_region(pp->msi_irq_in_use, pp->num_vectors, in dw_pcie_irq_domain_alloc()
199 raw_spin_unlock_irqrestore(&pp->lock, flags); in dw_pcie_irq_domain_alloc()
202 return -ENOSPC; in dw_pcie_irq_domain_alloc()
205 irq_domain_set_info(domain, virq + i, bit + i, in dw_pcie_irq_domain_alloc()
206 pp->msi_irq_chip, in dw_pcie_irq_domain_alloc()
213 static void dw_pcie_irq_domain_free(struct irq_domain *domain, in dw_pcie_irq_domain_free() argument
216 struct irq_data *d = irq_domain_get_irq_data(domain, virq); in dw_pcie_irq_domain_free()
217 struct pcie_port *pp = domain->host_data; in dw_pcie_irq_domain_free()
220 raw_spin_lock_irqsave(&pp->lock, flags); in dw_pcie_irq_domain_free()
222 bitmap_release_region(pp->msi_irq_in_use, d->hwirq, in dw_pcie_irq_domain_free()
225 raw_spin_unlock_irqrestore(&pp->lock, flags); in dw_pcie_irq_domain_free()
235 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_allocate_domains() local
236 struct fwnode_handle *fwnode = of_node_to_fwnode(pci->dev->of_node); in dw_pcie_allocate_domains()
238 pp->irq_domain = irq_domain_create_linear(fwnode, pp->num_vectors, in dw_pcie_allocate_domains()
240 if (!pp->irq_domain) { in dw_pcie_allocate_domains()
241 dev_err(pci->dev, "Failed to create IRQ domain\n"); in dw_pcie_allocate_domains()
242 return -ENOMEM; in dw_pcie_allocate_domains()
245 irq_domain_update_bus_token(pp->irq_domain, DOMAIN_BUS_NEXUS); in dw_pcie_allocate_domains()
247 pp->msi_domain = pci_msi_create_irq_domain(fwnode, in dw_pcie_allocate_domains()
249 pp->irq_domain); in dw_pcie_allocate_domains()
250 if (!pp->msi_domain) { in dw_pcie_allocate_domains()
251 dev_err(pci->dev, "Failed to create MSI domain\n"); in dw_pcie_allocate_domains()
252 irq_domain_remove(pp->irq_domain); in dw_pcie_allocate_domains()
253 return -ENOMEM; in dw_pcie_allocate_domains()
261 if (pp->msi_irq) { in dw_pcie_free_msi()
262 irq_set_chained_handler(pp->msi_irq, NULL); in dw_pcie_free_msi()
263 irq_set_handler_data(pp->msi_irq, NULL); in dw_pcie_free_msi()
266 irq_domain_remove(pp->msi_domain); in dw_pcie_free_msi()
267 irq_domain_remove(pp->irq_domain); in dw_pcie_free_msi()
269 if (pp->msi_data) { in dw_pcie_free_msi()
270 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_free_msi() local
271 struct device *dev = pci->dev; in dw_pcie_free_msi()
273 dma_unmap_single_attrs(dev, pp->msi_data, sizeof(pp->msi_msg), in dw_pcie_free_msi()
280 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_msi_init() local
281 u64 msi_target = (u64)pp->msi_data; in dw_pcie_msi_init()
287 dw_pcie_writel_dbi(pci, PCIE_MSI_ADDR_LO, lower_32_bits(msi_target)); in dw_pcie_msi_init()
288 dw_pcie_writel_dbi(pci, PCIE_MSI_ADDR_HI, upper_32_bits(msi_target)); in dw_pcie_msi_init()
294 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_host_init() local
295 struct device *dev = pci->dev; in dw_pcie_host_init()
296 struct device_node *np = dev->of_node; in dw_pcie_host_init()
303 raw_spin_lock_init(&pci->pp.lock); in dw_pcie_host_init()
307 pp->cfg0_size = resource_size(cfg_res); in dw_pcie_host_init()
308 pp->cfg0_base = cfg_res->start; in dw_pcie_host_init()
309 } else if (!pp->va_cfg0_base) { in dw_pcie_host_init()
315 return -ENOMEM; in dw_pcie_host_init()
317 pp->bridge = bridge; in dw_pcie_host_init()
320 resource_list_for_each_entry(win, &bridge->windows) { in dw_pcie_host_init()
321 switch (resource_type(win->res)) { in dw_pcie_host_init()
323 pp->io_size = resource_size(win->res); in dw_pcie_host_init()
324 pp->io_bus_addr = win->res->start - win->offset; in dw_pcie_host_init()
325 pp->io_base = pci_pio_to_address(win->res->start); in dw_pcie_host_init()
329 pp->cfg0_size = resource_size(win->res); in dw_pcie_host_init()
330 pp->cfg0_base = win->res->start; in dw_pcie_host_init()
331 if (!pci->dbi_base) { in dw_pcie_host_init()
332 pci->dbi_base = devm_pci_remap_cfgspace(dev, in dw_pcie_host_init()
333 pp->cfg0_base, in dw_pcie_host_init()
334 pp->cfg0_size); in dw_pcie_host_init()
335 if (!pci->dbi_base) { in dw_pcie_host_init()
337 return -ENOMEM; in dw_pcie_host_init()
344 if (!pp->va_cfg0_base) { in dw_pcie_host_init()
345 pp->va_cfg0_base = devm_pci_remap_cfgspace(dev, in dw_pcie_host_init()
346 pp->cfg0_base, pp->cfg0_size); in dw_pcie_host_init()
347 if (!pp->va_cfg0_base) { in dw_pcie_host_init()
349 return -ENOMEM; in dw_pcie_host_init()
353 ret = of_property_read_u32(np, "num-viewport", &pci->num_viewport); in dw_pcie_host_init()
355 pci->num_viewport = 2; in dw_pcie_host_init()
357 if (pci->link_gen < 1) in dw_pcie_host_init()
358 pci->link_gen = of_pci_get_max_link_speed(np); in dw_pcie_host_init()
366 if (!pp->ops->set_num_vectors) { in dw_pcie_host_init()
367 pp->num_vectors = MSI_DEF_NUM_VECTORS; in dw_pcie_host_init()
369 pp->ops->set_num_vectors(pp); in dw_pcie_host_init()
371 if (pp->num_vectors > MAX_MSI_IRQS || in dw_pcie_host_init()
372 pp->num_vectors == 0) { in dw_pcie_host_init()
375 return -EINVAL; in dw_pcie_host_init()
379 if (!pp->ops->msi_host_init) { in dw_pcie_host_init()
380 pp->msi_irq_chip = &dw_pci_msi_bottom_irq_chip; in dw_pcie_host_init()
386 if (pp->msi_irq) in dw_pcie_host_init()
387 irq_set_chained_handler_and_data(pp->msi_irq, in dw_pcie_host_init()
391 pp->msi_data = dma_map_single_attrs(pci->dev, &pp->msi_msg, in dw_pcie_host_init()
392 sizeof(pp->msi_msg), in dw_pcie_host_init()
395 ret = dma_mapping_error(pci->dev, pp->msi_data); in dw_pcie_host_init()
397 dev_err(pci->dev, "Failed to map MSI data\n"); in dw_pcie_host_init()
398 pp->msi_data = 0; in dw_pcie_host_init()
402 ret = pp->ops->msi_host_init(pp); in dw_pcie_host_init()
409 bridge->ops = &dw_pcie_ops; in dw_pcie_host_init()
410 bridge->child_ops = &dw_child_pcie_ops; in dw_pcie_host_init()
412 if (pp->ops->host_init) { in dw_pcie_host_init()
413 ret = pp->ops->host_init(pp); in dw_pcie_host_init()
418 bridge->sysdata = pp; in dw_pcie_host_init()
425 if (pci_msi_enabled() && !pp->ops->msi_host_init) in dw_pcie_host_init()
433 pci_stop_root_bus(pp->bridge->bus); in dw_pcie_host_deinit()
434 pci_remove_root_bus(pp->bridge->bus); in dw_pcie_host_deinit()
435 if (pci_msi_enabled() && !pp->ops->msi_host_init) in dw_pcie_host_deinit()
445 struct pcie_port *pp = bus->sysdata; in dw_pcie_other_conf_map_bus()
446 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_other_conf_map_bus() local
451 * SError upon PCI configuration transactions issued when the link in dw_pcie_other_conf_map_bus()
456 if (!dw_pcie_link_up(pci)) in dw_pcie_other_conf_map_bus()
459 busdev = PCIE_ATU_BUS(bus->number) | PCIE_ATU_DEV(PCI_SLOT(devfn)) | in dw_pcie_other_conf_map_bus()
462 if (pci_is_root_bus(bus->parent)) in dw_pcie_other_conf_map_bus()
468 dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX1, in dw_pcie_other_conf_map_bus()
469 type, pp->cfg0_base, in dw_pcie_other_conf_map_bus()
470 busdev, pp->cfg0_size); in dw_pcie_other_conf_map_bus()
472 return pp->va_cfg0_base + where; in dw_pcie_other_conf_map_bus()
479 struct pcie_port *pp = bus->sysdata; in dw_pcie_rd_other_conf()
480 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_rd_other_conf() local
484 if (!ret && pci->num_viewport <= 2) in dw_pcie_rd_other_conf()
485 dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX1, in dw_pcie_rd_other_conf()
486 PCIE_ATU_TYPE_IO, pp->io_base, in dw_pcie_rd_other_conf()
487 pp->io_bus_addr, pp->io_size); in dw_pcie_rd_other_conf()
496 struct pcie_port *pp = bus->sysdata; in dw_pcie_wr_other_conf()
497 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_wr_other_conf() local
501 if (!ret && pci->num_viewport <= 2) in dw_pcie_wr_other_conf()
502 dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX1, in dw_pcie_wr_other_conf()
503 PCIE_ATU_TYPE_IO, pp->io_base, in dw_pcie_wr_other_conf()
504 pp->io_bus_addr, pp->io_size); in dw_pcie_wr_other_conf()
517 struct pcie_port *pp = bus->sysdata; in dw_pcie_own_conf_map_bus()
518 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_own_conf_map_bus() local
523 return pci->dbi_base + where; in dw_pcie_own_conf_map_bus()
536 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_setup_rc() local
539 * Enable DBI read-only registers for writing/updating configuration. in dw_pcie_setup_rc()
542 dw_pcie_dbi_ro_wr_en(pci); in dw_pcie_setup_rc()
544 dw_pcie_setup(pci); in dw_pcie_setup_rc()
546 if (pci_msi_enabled() && !pp->ops->msi_host_init) { in dw_pcie_setup_rc()
547 num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL; in dw_pcie_setup_rc()
551 pp->irq_mask[ctrl] = ~0; in dw_pcie_setup_rc()
552 dw_pcie_writel_dbi(pci, PCIE_MSI_INTR0_MASK + in dw_pcie_setup_rc()
554 pp->irq_mask[ctrl]); in dw_pcie_setup_rc()
555 dw_pcie_writel_dbi(pci, PCIE_MSI_INTR0_ENABLE + in dw_pcie_setup_rc()
562 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0x00000004); in dw_pcie_setup_rc()
563 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_1, 0x00000000); in dw_pcie_setup_rc()
566 val = dw_pcie_readl_dbi(pci, PCI_INTERRUPT_LINE); in dw_pcie_setup_rc()
569 dw_pcie_writel_dbi(pci, PCI_INTERRUPT_LINE, val); in dw_pcie_setup_rc()
572 val = dw_pcie_readl_dbi(pci, PCI_PRIMARY_BUS); in dw_pcie_setup_rc()
575 dw_pcie_writel_dbi(pci, PCI_PRIMARY_BUS, val); in dw_pcie_setup_rc()
578 val = dw_pcie_readl_dbi(pci, PCI_COMMAND); in dw_pcie_setup_rc()
582 dw_pcie_writel_dbi(pci, PCI_COMMAND, val); in dw_pcie_setup_rc()
589 if (pp->bridge->child_ops == &dw_child_pcie_ops) { in dw_pcie_setup_rc()
593 resource_list_for_each_entry(tmp, &pp->bridge->windows) in dw_pcie_setup_rc()
594 if (resource_type(tmp->res) == IORESOURCE_MEM) in dw_pcie_setup_rc()
597 dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX0, in dw_pcie_setup_rc()
598 PCIE_ATU_TYPE_MEM, entry->res->start, in dw_pcie_setup_rc()
599 entry->res->start - entry->offset, in dw_pcie_setup_rc()
600 resource_size(entry->res)); in dw_pcie_setup_rc()
601 if (pci->num_viewport > 2) in dw_pcie_setup_rc()
602 dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX2, in dw_pcie_setup_rc()
603 PCIE_ATU_TYPE_IO, pp->io_base, in dw_pcie_setup_rc()
604 pp->io_bus_addr, pp->io_size); in dw_pcie_setup_rc()
607 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0); in dw_pcie_setup_rc()
610 dw_pcie_writew_dbi(pci, PCI_CLASS_DEVICE, PCI_CLASS_BRIDGE_PCI); in dw_pcie_setup_rc()
612 val = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL); in dw_pcie_setup_rc()
614 dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, val); in dw_pcie_setup_rc()
616 dw_pcie_dbi_ro_wr_dis(pci); in dw_pcie_setup_rc()