1 // SPDX-License-Identifier: GPL-2.0
3 * Synopsys DesignWare PCIe host controller driver
5 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
6 * https://www.samsung.com
8 * Author: Jingoo Han <jg1.han@samsung.com>
11 #include <linux/irqchip/chained_irq.h>
12 #include <linux/irqdomain.h>
13 #include <linux/msi.h>
14 #include <linux/of_address.h>
15 #include <linux/of_pci.h>
16 #include <linux/pci_regs.h>
17 #include <linux/platform_device.h>
19 #include "pcie-designware.h"
21 static struct pci_ops dw_pcie_ops;
22 static struct pci_ops dw_child_pcie_ops;
24 static void dw_msi_ack_irq(struct irq_data *d)
26 irq_chip_ack_parent(d);
29 static void dw_msi_mask_irq(struct irq_data *d)
32 irq_chip_mask_parent(d);
35 static void dw_msi_unmask_irq(struct irq_data *d)
37 pci_msi_unmask_irq(d);
38 irq_chip_unmask_parent(d);
41 static struct irq_chip dw_pcie_msi_irq_chip = {
43 .irq_ack = dw_msi_ack_irq,
44 .irq_mask = dw_msi_mask_irq,
45 .irq_unmask = dw_msi_unmask_irq,
48 static struct msi_domain_info dw_pcie_msi_domain_info = {
49 .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
50 MSI_FLAG_PCI_MSIX | MSI_FLAG_MULTI_PCI_MSI),
51 .chip = &dw_pcie_msi_irq_chip,
55 irqreturn_t dw_handle_msi_irq(struct dw_pcie_rp *pp)
59 u32 status, num_ctrls;
60 irqreturn_t ret = IRQ_NONE;
61 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
63 num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
65 for (i = 0; i < num_ctrls; i++) {
66 status = dw_pcie_readl_dbi(pci, PCIE_MSI_INTR0_STATUS +
67 (i * MSI_REG_CTRL_BLOCK_SIZE));
74 while ((pos = find_next_bit(&val, MAX_MSI_IRQS_PER_CTRL,
75 pos)) != MAX_MSI_IRQS_PER_CTRL) {
76 generic_handle_domain_irq(pp->irq_domain,
77 (i * MAX_MSI_IRQS_PER_CTRL) +
86 /* Chained MSI interrupt service routine */
87 static void dw_chained_msi_isr(struct irq_desc *desc)
89 struct irq_chip *chip = irq_desc_get_chip(desc);
90 struct dw_pcie_rp *pp;
92 chained_irq_enter(chip, desc);
94 pp = irq_desc_get_handler_data(desc);
95 dw_handle_msi_irq(pp);
97 chained_irq_exit(chip, desc);
100 static void dw_pci_setup_msi_msg(struct irq_data *d, struct msi_msg *msg)
102 struct dw_pcie_rp *pp = irq_data_get_irq_chip_data(d);
103 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
106 msi_target = (u64)pp->msi_data;
108 msg->address_lo = lower_32_bits(msi_target);
109 msg->address_hi = upper_32_bits(msi_target);
111 msg->data = d->hwirq;
113 dev_dbg(pci->dev, "msi#%d address_hi %#x address_lo %#x\n",
114 (int)d->hwirq, msg->address_hi, msg->address_lo);
117 static int dw_pci_msi_set_affinity(struct irq_data *d,
118 const struct cpumask *mask, bool force)
123 static void dw_pci_bottom_mask(struct irq_data *d)
125 struct dw_pcie_rp *pp = irq_data_get_irq_chip_data(d);
126 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
127 unsigned int res, bit, ctrl;
130 raw_spin_lock_irqsave(&pp->lock, flags);
132 ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL;
133 res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
134 bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
136 pp->irq_mask[ctrl] |= BIT(bit);
137 dw_pcie_writel_dbi(pci, PCIE_MSI_INTR0_MASK + res, pp->irq_mask[ctrl]);
139 raw_spin_unlock_irqrestore(&pp->lock, flags);
142 static void dw_pci_bottom_unmask(struct irq_data *d)
144 struct dw_pcie_rp *pp = irq_data_get_irq_chip_data(d);
145 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
146 unsigned int res, bit, ctrl;
149 raw_spin_lock_irqsave(&pp->lock, flags);
151 ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL;
152 res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
153 bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
155 pp->irq_mask[ctrl] &= ~BIT(bit);
156 dw_pcie_writel_dbi(pci, PCIE_MSI_INTR0_MASK + res, pp->irq_mask[ctrl]);
158 raw_spin_unlock_irqrestore(&pp->lock, flags);
161 static void dw_pci_bottom_ack(struct irq_data *d)
163 struct dw_pcie_rp *pp = irq_data_get_irq_chip_data(d);
164 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
165 unsigned int res, bit, ctrl;
167 ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL;
168 res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
169 bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
171 dw_pcie_writel_dbi(pci, PCIE_MSI_INTR0_STATUS + res, BIT(bit));
174 static struct irq_chip dw_pci_msi_bottom_irq_chip = {
176 .irq_ack = dw_pci_bottom_ack,
177 .irq_compose_msi_msg = dw_pci_setup_msi_msg,
178 .irq_set_affinity = dw_pci_msi_set_affinity,
179 .irq_mask = dw_pci_bottom_mask,
180 .irq_unmask = dw_pci_bottom_unmask,
183 static int dw_pcie_irq_domain_alloc(struct irq_domain *domain,
184 unsigned int virq, unsigned int nr_irqs,
187 struct dw_pcie_rp *pp = domain->host_data;
192 raw_spin_lock_irqsave(&pp->lock, flags);
194 bit = bitmap_find_free_region(pp->msi_irq_in_use, pp->num_vectors,
195 order_base_2(nr_irqs));
197 raw_spin_unlock_irqrestore(&pp->lock, flags);
202 for (i = 0; i < nr_irqs; i++)
203 irq_domain_set_info(domain, virq + i, bit + i,
211 static void dw_pcie_irq_domain_free(struct irq_domain *domain,
212 unsigned int virq, unsigned int nr_irqs)
214 struct irq_data *d = irq_domain_get_irq_data(domain, virq);
215 struct dw_pcie_rp *pp = domain->host_data;
218 raw_spin_lock_irqsave(&pp->lock, flags);
220 bitmap_release_region(pp->msi_irq_in_use, d->hwirq,
221 order_base_2(nr_irqs));
223 raw_spin_unlock_irqrestore(&pp->lock, flags);
226 static const struct irq_domain_ops dw_pcie_msi_domain_ops = {
227 .alloc = dw_pcie_irq_domain_alloc,
228 .free = dw_pcie_irq_domain_free,
231 int dw_pcie_allocate_domains(struct dw_pcie_rp *pp)
233 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
234 struct fwnode_handle *fwnode = of_node_to_fwnode(pci->dev->of_node);
236 pp->irq_domain = irq_domain_create_linear(fwnode, pp->num_vectors,
237 &dw_pcie_msi_domain_ops, pp);
238 if (!pp->irq_domain) {
239 dev_err(pci->dev, "Failed to create IRQ domain\n");
243 irq_domain_update_bus_token(pp->irq_domain, DOMAIN_BUS_NEXUS);
245 pp->msi_domain = pci_msi_create_irq_domain(fwnode,
246 &dw_pcie_msi_domain_info,
248 if (!pp->msi_domain) {
249 dev_err(pci->dev, "Failed to create MSI domain\n");
250 irq_domain_remove(pp->irq_domain);
257 static void dw_pcie_free_msi(struct dw_pcie_rp *pp)
261 for (ctrl = 0; ctrl < MAX_MSI_CTRLS; ctrl++) {
262 if (pp->msi_irq[ctrl] > 0)
263 irq_set_chained_handler_and_data(pp->msi_irq[ctrl],
267 irq_domain_remove(pp->msi_domain);
268 irq_domain_remove(pp->irq_domain);
271 static void dw_pcie_msi_init(struct dw_pcie_rp *pp)
273 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
274 u64 msi_target = (u64)pp->msi_data;
276 if (!pci_msi_enabled() || !pp->has_msi_ctrl)
279 /* Program the msi_data */
280 dw_pcie_writel_dbi(pci, PCIE_MSI_ADDR_LO, lower_32_bits(msi_target));
281 dw_pcie_writel_dbi(pci, PCIE_MSI_ADDR_HI, upper_32_bits(msi_target));
284 static int dw_pcie_parse_split_msi_irq(struct dw_pcie_rp *pp)
286 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
287 struct device *dev = pci->dev;
288 struct platform_device *pdev = to_platform_device(dev);
289 u32 ctrl, max_vectors;
292 /* Parse any "msiX" IRQs described in the devicetree */
293 for (ctrl = 0; ctrl < MAX_MSI_CTRLS; ctrl++) {
294 char msi_name[] = "msiX";
296 msi_name[3] = '0' + ctrl;
297 irq = platform_get_irq_byname_optional(pdev, msi_name);
301 return dev_err_probe(dev, irq,
302 "Failed to parse MSI IRQ '%s'\n",
305 pp->msi_irq[ctrl] = irq;
308 /* If no "msiX" IRQs, caller should fallback to "msi" IRQ */
312 max_vectors = ctrl * MAX_MSI_IRQS_PER_CTRL;
313 if (pp->num_vectors > max_vectors) {
314 dev_warn(dev, "Exceeding number of MSI vectors, limiting to %u\n",
316 pp->num_vectors = max_vectors;
318 if (!pp->num_vectors)
319 pp->num_vectors = max_vectors;
324 static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)
326 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
327 struct device *dev = pci->dev;
328 struct platform_device *pdev = to_platform_device(dev);
333 for (ctrl = 0; ctrl < MAX_MSI_CTRLS; ctrl++)
334 pp->irq_mask[ctrl] = ~0;
336 if (!pp->msi_irq[0]) {
337 ret = dw_pcie_parse_split_msi_irq(pp);
338 if (ret < 0 && ret != -ENXIO)
342 if (!pp->num_vectors)
343 pp->num_vectors = MSI_DEF_NUM_VECTORS;
344 num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
346 if (!pp->msi_irq[0]) {
347 pp->msi_irq[0] = platform_get_irq_byname_optional(pdev, "msi");
348 if (pp->msi_irq[0] < 0) {
349 pp->msi_irq[0] = platform_get_irq(pdev, 0);
350 if (pp->msi_irq[0] < 0)
351 return pp->msi_irq[0];
355 dev_dbg(dev, "Using %d MSI vectors\n", pp->num_vectors);
357 pp->msi_irq_chip = &dw_pci_msi_bottom_irq_chip;
359 ret = dw_pcie_allocate_domains(pp);
363 for (ctrl = 0; ctrl < num_ctrls; ctrl++) {
364 if (pp->msi_irq[ctrl] > 0)
365 irq_set_chained_handler_and_data(pp->msi_irq[ctrl],
366 dw_chained_msi_isr, pp);
370 * Even though the iMSI-RX Module supports 64-bit addresses some
371 * peripheral PCIe devices may lack 64-bit message support. In
372 * order not to miss MSI TLPs from those devices the MSI target
373 * address has to be within the lowest 4GB.
375 * Note until there is a better alternative found the reservation is
376 * done by allocating from the artificially limited DMA-coherent
379 ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
381 dev_warn(dev, "Failed to set DMA mask to 32-bit. Devices with only 32-bit MSI support may not work properly\n");
383 msi_vaddr = dmam_alloc_coherent(dev, sizeof(u64), &pp->msi_data,
386 dev_err(dev, "Failed to alloc and map MSI data\n");
387 dw_pcie_free_msi(pp);
394 int dw_pcie_host_init(struct dw_pcie_rp *pp)
396 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
397 struct device *dev = pci->dev;
398 struct device_node *np = dev->of_node;
399 struct platform_device *pdev = to_platform_device(dev);
400 struct resource_entry *win;
401 struct pci_host_bridge *bridge;
402 struct resource *res;
405 raw_spin_lock_init(&pp->lock);
407 ret = dw_pcie_get_resources(pci);
411 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "config");
413 pp->cfg0_size = resource_size(res);
414 pp->cfg0_base = res->start;
416 pp->va_cfg0_base = devm_pci_remap_cfg_resource(dev, res);
417 if (IS_ERR(pp->va_cfg0_base))
418 return PTR_ERR(pp->va_cfg0_base);
420 dev_err(dev, "Missing *config* reg space\n");
424 bridge = devm_pci_alloc_host_bridge(dev, 0);
430 /* Get the I/O range from DT */
431 win = resource_list_first_type(&bridge->windows, IORESOURCE_IO);
433 pp->io_size = resource_size(win->res);
434 pp->io_bus_addr = win->res->start - win->offset;
435 pp->io_base = pci_pio_to_address(win->res->start);
438 /* Set default bus ops */
439 bridge->ops = &dw_pcie_ops;
440 bridge->child_ops = &dw_child_pcie_ops;
442 if (pp->ops->host_init) {
443 ret = pp->ops->host_init(pp);
448 if (pci_msi_enabled()) {
449 pp->has_msi_ctrl = !(pp->ops->msi_host_init ||
450 of_property_read_bool(np, "msi-parent") ||
451 of_property_read_bool(np, "msi-map"));
454 * For the has_msi_ctrl case the default assignment is handled
455 * in the dw_pcie_msi_host_init().
457 if (!pp->has_msi_ctrl && !pp->num_vectors) {
458 pp->num_vectors = MSI_DEF_NUM_VECTORS;
459 } else if (pp->num_vectors > MAX_MSI_IRQS) {
460 dev_err(dev, "Invalid number of vectors\n");
462 goto err_deinit_host;
465 if (pp->ops->msi_host_init) {
466 ret = pp->ops->msi_host_init(pp);
468 goto err_deinit_host;
469 } else if (pp->has_msi_ctrl) {
470 ret = dw_pcie_msi_host_init(pp);
472 goto err_deinit_host;
476 dw_pcie_version_detect(pci);
478 dw_pcie_iatu_detect(pci);
480 ret = dw_pcie_edma_detect(pci);
484 ret = dw_pcie_setup_rc(pp);
486 goto err_remove_edma;
488 if (dw_pcie_link_up(pci)) {
489 dw_pcie_print_link_status(pci);
491 ret = dw_pcie_start_link(pci);
493 goto err_remove_edma;
495 if (pci->ops && pci->ops->start_link) {
496 ret = dw_pcie_wait_for_link(pci);
502 bridge->sysdata = pp;
504 ret = pci_host_probe(bridge);
511 dw_pcie_stop_link(pci);
514 dw_pcie_edma_remove(pci);
517 if (pp->has_msi_ctrl)
518 dw_pcie_free_msi(pp);
521 if (pp->ops->host_deinit)
522 pp->ops->host_deinit(pp);
526 EXPORT_SYMBOL_GPL(dw_pcie_host_init);
528 void dw_pcie_host_deinit(struct dw_pcie_rp *pp)
530 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
532 pci_stop_root_bus(pp->bridge->bus);
533 pci_remove_root_bus(pp->bridge->bus);
535 dw_pcie_stop_link(pci);
537 dw_pcie_edma_remove(pci);
539 if (pp->has_msi_ctrl)
540 dw_pcie_free_msi(pp);
542 if (pp->ops->host_deinit)
543 pp->ops->host_deinit(pp);
545 EXPORT_SYMBOL_GPL(dw_pcie_host_deinit);
547 static void __iomem *dw_pcie_other_conf_map_bus(struct pci_bus *bus,
548 unsigned int devfn, int where)
550 struct dw_pcie_rp *pp = bus->sysdata;
551 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
556 * Checking whether the link is up here is a last line of defense
557 * against platforms that forward errors on the system bus as
558 * SError upon PCI configuration transactions issued when the link
559 * is down. This check is racy by definition and does not stop
560 * the system from triggering an SError if the link goes down
561 * after this check is performed.
563 if (!dw_pcie_link_up(pci))
566 busdev = PCIE_ATU_BUS(bus->number) | PCIE_ATU_DEV(PCI_SLOT(devfn)) |
567 PCIE_ATU_FUNC(PCI_FUNC(devfn));
569 if (pci_is_root_bus(bus->parent))
570 type = PCIE_ATU_TYPE_CFG0;
572 type = PCIE_ATU_TYPE_CFG1;
574 ret = dw_pcie_prog_outbound_atu(pci, 0, type, pp->cfg0_base, busdev,
579 return pp->va_cfg0_base + where;
582 static int dw_pcie_rd_other_conf(struct pci_bus *bus, unsigned int devfn,
583 int where, int size, u32 *val)
585 struct dw_pcie_rp *pp = bus->sysdata;
586 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
589 ret = pci_generic_config_read(bus, devfn, where, size, val);
590 if (ret != PCIBIOS_SUCCESSFUL)
593 if (pp->cfg0_io_shared) {
594 ret = dw_pcie_prog_outbound_atu(pci, 0, PCIE_ATU_TYPE_IO,
595 pp->io_base, pp->io_bus_addr,
598 return PCIBIOS_SET_FAILED;
601 return PCIBIOS_SUCCESSFUL;
604 static int dw_pcie_wr_other_conf(struct pci_bus *bus, unsigned int devfn,
605 int where, int size, u32 val)
607 struct dw_pcie_rp *pp = bus->sysdata;
608 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
611 ret = pci_generic_config_write(bus, devfn, where, size, val);
612 if (ret != PCIBIOS_SUCCESSFUL)
615 if (pp->cfg0_io_shared) {
616 ret = dw_pcie_prog_outbound_atu(pci, 0, PCIE_ATU_TYPE_IO,
617 pp->io_base, pp->io_bus_addr,
620 return PCIBIOS_SET_FAILED;
623 return PCIBIOS_SUCCESSFUL;
626 static struct pci_ops dw_child_pcie_ops = {
627 .map_bus = dw_pcie_other_conf_map_bus,
628 .read = dw_pcie_rd_other_conf,
629 .write = dw_pcie_wr_other_conf,
632 void __iomem *dw_pcie_own_conf_map_bus(struct pci_bus *bus, unsigned int devfn, int where)
634 struct dw_pcie_rp *pp = bus->sysdata;
635 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
637 if (PCI_SLOT(devfn) > 0)
640 return pci->dbi_base + where;
642 EXPORT_SYMBOL_GPL(dw_pcie_own_conf_map_bus);
644 static struct pci_ops dw_pcie_ops = {
645 .map_bus = dw_pcie_own_conf_map_bus,
646 .read = pci_generic_config_read,
647 .write = pci_generic_config_write,
650 static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp)
652 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
653 struct resource_entry *entry;
656 /* Note the very first outbound ATU is used for CFG IOs */
657 if (!pci->num_ob_windows) {
658 dev_err(pci->dev, "No outbound iATU found\n");
663 * Ensure all out/inbound windows are disabled before proceeding with
664 * the MEM/IO (dma-)ranges setups.
666 for (i = 0; i < pci->num_ob_windows; i++)
667 dw_pcie_disable_atu(pci, PCIE_ATU_REGION_DIR_OB, i);
669 for (i = 0; i < pci->num_ib_windows; i++)
670 dw_pcie_disable_atu(pci, PCIE_ATU_REGION_DIR_IB, i);
673 resource_list_for_each_entry(entry, &pp->bridge->windows) {
674 if (resource_type(entry->res) != IORESOURCE_MEM)
677 if (pci->num_ob_windows <= ++i)
680 ret = dw_pcie_prog_outbound_atu(pci, i, PCIE_ATU_TYPE_MEM,
682 entry->res->start - entry->offset,
683 resource_size(entry->res));
685 dev_err(pci->dev, "Failed to set MEM range %pr\n",
692 if (pci->num_ob_windows > ++i) {
693 ret = dw_pcie_prog_outbound_atu(pci, i, PCIE_ATU_TYPE_IO,
698 dev_err(pci->dev, "Failed to set IO range %pr\n",
703 pp->cfg0_io_shared = true;
707 if (pci->num_ob_windows <= i)
708 dev_warn(pci->dev, "Ranges exceed outbound iATU size (%d)\n",
709 pci->num_ob_windows);
712 resource_list_for_each_entry(entry, &pp->bridge->dma_ranges) {
713 if (resource_type(entry->res) != IORESOURCE_MEM)
716 if (pci->num_ib_windows <= i)
719 ret = dw_pcie_prog_inbound_atu(pci, i++, PCIE_ATU_TYPE_MEM,
721 entry->res->start - entry->offset,
722 resource_size(entry->res));
724 dev_err(pci->dev, "Failed to set DMA range %pr\n",
730 if (pci->num_ib_windows <= i)
731 dev_warn(pci->dev, "Dma-ranges exceed inbound iATU size (%u)\n",
732 pci->num_ib_windows);
737 int dw_pcie_setup_rc(struct dw_pcie_rp *pp)
739 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
740 u32 val, ctrl, num_ctrls;
744 * Enable DBI read-only registers for writing/updating configuration.
745 * Write permission gets disabled towards the end of this function.
747 dw_pcie_dbi_ro_wr_en(pci);
751 if (pp->has_msi_ctrl) {
752 num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
754 /* Initialize IRQ Status array */
755 for (ctrl = 0; ctrl < num_ctrls; ctrl++) {
756 dw_pcie_writel_dbi(pci, PCIE_MSI_INTR0_MASK +
757 (ctrl * MSI_REG_CTRL_BLOCK_SIZE),
759 dw_pcie_writel_dbi(pci, PCIE_MSI_INTR0_ENABLE +
760 (ctrl * MSI_REG_CTRL_BLOCK_SIZE),
765 dw_pcie_msi_init(pp);
768 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0x00000004);
769 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_1, 0x00000000);
771 /* Setup interrupt pins */
772 val = dw_pcie_readl_dbi(pci, PCI_INTERRUPT_LINE);
775 dw_pcie_writel_dbi(pci, PCI_INTERRUPT_LINE, val);
777 /* Setup bus numbers */
778 val = dw_pcie_readl_dbi(pci, PCI_PRIMARY_BUS);
781 dw_pcie_writel_dbi(pci, PCI_PRIMARY_BUS, val);
783 /* Setup command register */
784 val = dw_pcie_readl_dbi(pci, PCI_COMMAND);
786 val |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
787 PCI_COMMAND_MASTER | PCI_COMMAND_SERR;
788 dw_pcie_writel_dbi(pci, PCI_COMMAND, val);
791 * If the platform provides its own child bus config accesses, it means
792 * the platform uses its own address translation component rather than
793 * ATU, so we should not program the ATU here.
795 if (pp->bridge->child_ops == &dw_child_pcie_ops) {
796 ret = dw_pcie_iatu_setup(pp);
801 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0);
803 /* Program correct class for RC */
804 dw_pcie_writew_dbi(pci, PCI_CLASS_DEVICE, PCI_CLASS_BRIDGE_PCI);
806 val = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
807 val |= PORT_LOGIC_SPEED_CHANGE;
808 dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, val);
810 dw_pcie_dbi_ro_wr_dis(pci);
814 EXPORT_SYMBOL_GPL(dw_pcie_setup_rc);