Lines Matching refs:pp
23 static int dw_pcie_rd_own_conf(struct pcie_port *pp, int where, int size, in dw_pcie_rd_own_conf() argument
28 if (pp->ops->rd_own_conf) in dw_pcie_rd_own_conf()
29 return pp->ops->rd_own_conf(pp, where, size, val); in dw_pcie_rd_own_conf()
31 pci = to_dw_pcie_from_pp(pp); in dw_pcie_rd_own_conf()
35 static int dw_pcie_wr_own_conf(struct pcie_port *pp, int where, int size, in dw_pcie_wr_own_conf() argument
40 if (pp->ops->wr_own_conf) in dw_pcie_wr_own_conf()
41 return pp->ops->wr_own_conf(pp, where, size, val); in dw_pcie_wr_own_conf()
43 pci = to_dw_pcie_from_pp(pp); in dw_pcie_wr_own_conf()
78 irqreturn_t dw_handle_msi_irq(struct pcie_port *pp) in dw_handle_msi_irq() argument
84 num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL; in dw_handle_msi_irq()
87 dw_pcie_rd_own_conf(pp, PCIE_MSI_INTR0_STATUS + in dw_handle_msi_irq()
98 irq = irq_find_mapping(pp->irq_domain, in dw_handle_msi_irq()
102 dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_STATUS + in dw_handle_msi_irq()
116 struct pcie_port *pp; in dw_chained_msi_isr() local
120 pp = irq_desc_get_handler_data(desc); in dw_chained_msi_isr()
121 dw_handle_msi_irq(pp); in dw_chained_msi_isr()
128 struct pcie_port *pp = irq_data_get_irq_chip_data(data); in dw_pci_setup_msi_msg() local
129 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pci_setup_msi_msg()
132 if (pp->ops->get_msi_addr) in dw_pci_setup_msi_msg()
133 msi_target = pp->ops->get_msi_addr(pp); in dw_pci_setup_msi_msg()
135 msi_target = (u64)pp->msi_data; in dw_pci_setup_msi_msg()
140 if (pp->ops->get_msi_data) in dw_pci_setup_msi_msg()
141 msg->data = pp->ops->get_msi_data(pp, data->hwirq); in dw_pci_setup_msi_msg()
157 struct pcie_port *pp = irq_data_get_irq_chip_data(data); in dw_pci_bottom_mask() local
161 raw_spin_lock_irqsave(&pp->lock, flags); in dw_pci_bottom_mask()
163 if (pp->ops->msi_clear_irq) { in dw_pci_bottom_mask()
164 pp->ops->msi_clear_irq(pp, data->hwirq); in dw_pci_bottom_mask()
170 pp->irq_status[ctrl] &= ~(1 << bit); in dw_pci_bottom_mask()
171 dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE + res, 4, in dw_pci_bottom_mask()
172 pp->irq_status[ctrl]); in dw_pci_bottom_mask()
175 raw_spin_unlock_irqrestore(&pp->lock, flags); in dw_pci_bottom_mask()
180 struct pcie_port *pp = irq_data_get_irq_chip_data(data); in dw_pci_bottom_unmask() local
184 raw_spin_lock_irqsave(&pp->lock, flags); in dw_pci_bottom_unmask()
186 if (pp->ops->msi_set_irq) { in dw_pci_bottom_unmask()
187 pp->ops->msi_set_irq(pp, data->hwirq); in dw_pci_bottom_unmask()
193 pp->irq_status[ctrl] |= 1 << bit; in dw_pci_bottom_unmask()
194 dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE + res, 4, in dw_pci_bottom_unmask()
195 pp->irq_status[ctrl]); in dw_pci_bottom_unmask()
198 raw_spin_unlock_irqrestore(&pp->lock, flags); in dw_pci_bottom_unmask()
204 struct pcie_port *pp; in dw_pci_bottom_ack() local
206 pp = msi_desc_to_pci_sysdata(msi); in dw_pci_bottom_ack()
208 if (pp->ops->msi_irq_ack) in dw_pci_bottom_ack()
209 pp->ops->msi_irq_ack(d->hwirq, pp); in dw_pci_bottom_ack()
225 struct pcie_port *pp = domain->host_data; in dw_pcie_irq_domain_alloc() local
230 raw_spin_lock_irqsave(&pp->lock, flags); in dw_pcie_irq_domain_alloc()
232 bit = bitmap_find_free_region(pp->msi_irq_in_use, pp->num_vectors, in dw_pcie_irq_domain_alloc()
235 raw_spin_unlock_irqrestore(&pp->lock, flags); in dw_pcie_irq_domain_alloc()
243 pp, handle_edge_irq, in dw_pcie_irq_domain_alloc()
253 struct pcie_port *pp = irq_data_get_irq_chip_data(data); in dw_pcie_irq_domain_free() local
256 raw_spin_lock_irqsave(&pp->lock, flags); in dw_pcie_irq_domain_free()
258 bitmap_release_region(pp->msi_irq_in_use, data->hwirq, in dw_pcie_irq_domain_free()
261 raw_spin_unlock_irqrestore(&pp->lock, flags); in dw_pcie_irq_domain_free()
269 int dw_pcie_allocate_domains(struct pcie_port *pp) in dw_pcie_allocate_domains() argument
271 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_allocate_domains()
274 pp->irq_domain = irq_domain_create_linear(fwnode, pp->num_vectors, in dw_pcie_allocate_domains()
275 &dw_pcie_msi_domain_ops, pp); in dw_pcie_allocate_domains()
276 if (!pp->irq_domain) { in dw_pcie_allocate_domains()
281 pp->msi_domain = pci_msi_create_irq_domain(fwnode, in dw_pcie_allocate_domains()
283 pp->irq_domain); in dw_pcie_allocate_domains()
284 if (!pp->msi_domain) { in dw_pcie_allocate_domains()
286 irq_domain_remove(pp->irq_domain); in dw_pcie_allocate_domains()
293 void dw_pcie_free_msi(struct pcie_port *pp) in dw_pcie_free_msi() argument
295 irq_set_chained_handler(pp->msi_irq, NULL); in dw_pcie_free_msi()
296 irq_set_handler_data(pp->msi_irq, NULL); in dw_pcie_free_msi()
298 irq_domain_remove(pp->msi_domain); in dw_pcie_free_msi()
299 irq_domain_remove(pp->irq_domain); in dw_pcie_free_msi()
302 void dw_pcie_msi_init(struct pcie_port *pp) in dw_pcie_msi_init() argument
304 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_msi_init()
310 pp->msi_data = dma_map_page(dev, page, 0, PAGE_SIZE, DMA_FROM_DEVICE); in dw_pcie_msi_init()
311 if (dma_mapping_error(dev, pp->msi_data)) { in dw_pcie_msi_init()
316 msi_target = (u64)pp->msi_data; in dw_pcie_msi_init()
319 dw_pcie_wr_own_conf(pp, PCIE_MSI_ADDR_LO, 4, in dw_pcie_msi_init()
321 dw_pcie_wr_own_conf(pp, PCIE_MSI_ADDR_HI, 4, in dw_pcie_msi_init()
325 int dw_pcie_host_init(struct pcie_port *pp) in dw_pcie_host_init() argument
327 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_host_init()
337 raw_spin_lock_init(&pci->pp.lock); in dw_pcie_host_init()
341 pp->cfg0_size = resource_size(cfg_res) >> 1; in dw_pcie_host_init()
342 pp->cfg1_size = resource_size(cfg_res) >> 1; in dw_pcie_host_init()
343 pp->cfg0_base = cfg_res->start; in dw_pcie_host_init()
344 pp->cfg1_base = cfg_res->start + pp->cfg0_size; in dw_pcie_host_init()
345 } else if (!pp->va_cfg0_base) { in dw_pcie_host_init()
354 &bridge->windows, &pp->io_base); in dw_pcie_host_init()
367 pp->io_base); in dw_pcie_host_init()
373 pp->io = win->res; in dw_pcie_host_init()
374 pp->io->name = "I/O"; in dw_pcie_host_init()
375 pp->io_size = resource_size(pp->io); in dw_pcie_host_init()
376 pp->io_bus_addr = pp->io->start - win->offset; in dw_pcie_host_init()
380 pp->mem = win->res; in dw_pcie_host_init()
381 pp->mem->name = "MEM"; in dw_pcie_host_init()
382 pp->mem_size = resource_size(pp->mem); in dw_pcie_host_init()
383 pp->mem_bus_addr = pp->mem->start - win->offset; in dw_pcie_host_init()
386 pp->cfg = win->res; in dw_pcie_host_init()
387 pp->cfg0_size = resource_size(pp->cfg) >> 1; in dw_pcie_host_init()
388 pp->cfg1_size = resource_size(pp->cfg) >> 1; in dw_pcie_host_init()
389 pp->cfg0_base = pp->cfg->start; in dw_pcie_host_init()
390 pp->cfg1_base = pp->cfg->start + pp->cfg0_size; in dw_pcie_host_init()
393 pp->busn = win->res; in dw_pcie_host_init()
400 pp->cfg->start, in dw_pcie_host_init()
401 resource_size(pp->cfg)); in dw_pcie_host_init()
409 pp->mem_base = pp->mem->start; in dw_pcie_host_init()
411 if (!pp->va_cfg0_base) { in dw_pcie_host_init()
412 pp->va_cfg0_base = devm_pci_remap_cfgspace(dev, in dw_pcie_host_init()
413 pp->cfg0_base, pp->cfg0_size); in dw_pcie_host_init()
414 if (!pp->va_cfg0_base) { in dw_pcie_host_init()
421 if (!pp->va_cfg1_base) { in dw_pcie_host_init()
422 pp->va_cfg1_base = devm_pci_remap_cfgspace(dev, in dw_pcie_host_init()
423 pp->cfg1_base, in dw_pcie_host_init()
424 pp->cfg1_size); in dw_pcie_host_init()
425 if (!pp->va_cfg1_base) { in dw_pcie_host_init()
442 if (!pp->ops->set_num_vectors) { in dw_pcie_host_init()
443 pp->num_vectors = MSI_DEF_NUM_VECTORS; in dw_pcie_host_init()
445 pp->ops->set_num_vectors(pp); in dw_pcie_host_init()
447 if (pp->num_vectors > MAX_MSI_IRQS || in dw_pcie_host_init()
448 pp->num_vectors == 0) { in dw_pcie_host_init()
455 if (!pp->ops->msi_host_init) { in dw_pcie_host_init()
456 ret = dw_pcie_allocate_domains(pp); in dw_pcie_host_init()
460 if (pp->msi_irq) in dw_pcie_host_init()
461 irq_set_chained_handler_and_data(pp->msi_irq, in dw_pcie_host_init()
463 pp); in dw_pcie_host_init()
465 ret = pp->ops->msi_host_init(pp); in dw_pcie_host_init()
471 if (pp->ops->host_init) { in dw_pcie_host_init()
472 ret = pp->ops->host_init(pp); in dw_pcie_host_init()
477 pp->root_bus_nr = pp->busn->start; in dw_pcie_host_init()
480 bridge->sysdata = pp; in dw_pcie_host_init()
481 bridge->busnr = pp->root_bus_nr; in dw_pcie_host_init()
492 if (pp->ops->scan_bus) in dw_pcie_host_init()
493 pp->ops->scan_bus(pp); in dw_pcie_host_init()
509 static int dw_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus, in dw_pcie_rd_other_conf() argument
516 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_rd_other_conf()
518 if (pp->ops->rd_other_conf) in dw_pcie_rd_other_conf()
519 return pp->ops->rd_other_conf(pp, bus, devfn, where, size, val); in dw_pcie_rd_other_conf()
524 if (bus->parent->number == pp->root_bus_nr) { in dw_pcie_rd_other_conf()
526 cpu_addr = pp->cfg0_base; in dw_pcie_rd_other_conf()
527 cfg_size = pp->cfg0_size; in dw_pcie_rd_other_conf()
528 va_cfg_base = pp->va_cfg0_base; in dw_pcie_rd_other_conf()
531 cpu_addr = pp->cfg1_base; in dw_pcie_rd_other_conf()
532 cfg_size = pp->cfg1_size; in dw_pcie_rd_other_conf()
533 va_cfg_base = pp->va_cfg1_base; in dw_pcie_rd_other_conf()
542 PCIE_ATU_TYPE_IO, pp->io_base, in dw_pcie_rd_other_conf()
543 pp->io_bus_addr, pp->io_size); in dw_pcie_rd_other_conf()
548 static int dw_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus, in dw_pcie_wr_other_conf() argument
555 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_wr_other_conf()
557 if (pp->ops->wr_other_conf) in dw_pcie_wr_other_conf()
558 return pp->ops->wr_other_conf(pp, bus, devfn, where, size, val); in dw_pcie_wr_other_conf()
563 if (bus->parent->number == pp->root_bus_nr) { in dw_pcie_wr_other_conf()
565 cpu_addr = pp->cfg0_base; in dw_pcie_wr_other_conf()
566 cfg_size = pp->cfg0_size; in dw_pcie_wr_other_conf()
567 va_cfg_base = pp->va_cfg0_base; in dw_pcie_wr_other_conf()
570 cpu_addr = pp->cfg1_base; in dw_pcie_wr_other_conf()
571 cfg_size = pp->cfg1_size; in dw_pcie_wr_other_conf()
572 va_cfg_base = pp->va_cfg1_base; in dw_pcie_wr_other_conf()
581 PCIE_ATU_TYPE_IO, pp->io_base, in dw_pcie_wr_other_conf()
582 pp->io_bus_addr, pp->io_size); in dw_pcie_wr_other_conf()
587 static int dw_pcie_valid_device(struct pcie_port *pp, struct pci_bus *bus, in dw_pcie_valid_device() argument
590 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_valid_device()
593 if (bus->number != pp->root_bus_nr) { in dw_pcie_valid_device()
599 if (bus->number == pp->root_bus_nr && dev > 0) in dw_pcie_valid_device()
608 struct pcie_port *pp = bus->sysdata; in dw_pcie_rd_conf() local
610 if (!dw_pcie_valid_device(pp, bus, PCI_SLOT(devfn))) { in dw_pcie_rd_conf()
615 if (bus->number == pp->root_bus_nr) in dw_pcie_rd_conf()
616 return dw_pcie_rd_own_conf(pp, where, size, val); in dw_pcie_rd_conf()
618 return dw_pcie_rd_other_conf(pp, bus, devfn, where, size, val); in dw_pcie_rd_conf()
624 struct pcie_port *pp = bus->sysdata; in dw_pcie_wr_conf() local
626 if (!dw_pcie_valid_device(pp, bus, PCI_SLOT(devfn))) in dw_pcie_wr_conf()
629 if (bus->number == pp->root_bus_nr) in dw_pcie_wr_conf()
630 return dw_pcie_wr_own_conf(pp, where, size, val); in dw_pcie_wr_conf()
632 return dw_pcie_wr_other_conf(pp, bus, devfn, where, size, val); in dw_pcie_wr_conf()
651 void dw_pcie_setup_rc(struct pcie_port *pp) in dw_pcie_setup_rc() argument
654 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in dw_pcie_setup_rc()
658 num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL; in dw_pcie_setup_rc()
662 dw_pcie_rd_own_conf(pp, PCIE_MSI_INTR0_ENABLE + in dw_pcie_setup_rc()
664 4, &pp->irq_status[ctrl]); in dw_pcie_setup_rc()
696 if (!pp->ops->rd_other_conf) { in dw_pcie_setup_rc()
703 PCIE_ATU_TYPE_MEM, pp->mem_base, in dw_pcie_setup_rc()
704 pp->mem_bus_addr, pp->mem_size); in dw_pcie_setup_rc()
707 PCIE_ATU_TYPE_IO, pp->io_base, in dw_pcie_setup_rc()
708 pp->io_bus_addr, pp->io_size); in dw_pcie_setup_rc()
711 dw_pcie_wr_own_conf(pp, PCI_BASE_ADDRESS_0, 4, 0); in dw_pcie_setup_rc()
716 dw_pcie_wr_own_conf(pp, PCI_CLASS_DEVICE, 2, PCI_CLASS_BRIDGE_PCI); in dw_pcie_setup_rc()
720 dw_pcie_rd_own_conf(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, 4, &val); in dw_pcie_setup_rc()
722 dw_pcie_wr_own_conf(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, 4, val); in dw_pcie_setup_rc()