diff options
Diffstat (limited to 'drivers/pci/host/pcie-designware.c')
-rw-r--r-- | drivers/pci/host/pcie-designware.c | 134 |
1 files changed, 102 insertions, 32 deletions
diff --git a/drivers/pci/host/pcie-designware.c b/drivers/pci/host/pcie-designware.c index 1eaf4df3618a..52bd3a143563 100644 --- a/drivers/pci/host/pcie-designware.c +++ b/drivers/pci/host/pcie-designware.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/of_pci.h> | 20 | #include <linux/of_pci.h> |
21 | #include <linux/pci.h> | 21 | #include <linux/pci.h> |
22 | #include <linux/pci_regs.h> | 22 | #include <linux/pci_regs.h> |
23 | #include <linux/platform_device.h> | ||
23 | #include <linux/types.h> | 24 | #include <linux/types.h> |
24 | 25 | ||
25 | #include "pcie-designware.h" | 26 | #include "pcie-designware.h" |
@@ -217,27 +218,47 @@ static int find_valid_pos0(struct pcie_port *pp, int msgvec, int pos, int *pos0) | |||
217 | return 0; | 218 | return 0; |
218 | } | 219 | } |
219 | 220 | ||
221 | static void dw_pcie_msi_clear_irq(struct pcie_port *pp, int irq) | ||
222 | { | ||
223 | unsigned int res, bit, val; | ||
224 | |||
225 | res = (irq / 32) * 12; | ||
226 | bit = irq % 32; | ||
227 | dw_pcie_rd_own_conf(pp, PCIE_MSI_INTR0_ENABLE + res, 4, &val); | ||
228 | val &= ~(1 << bit); | ||
229 | dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE + res, 4, val); | ||
230 | } | ||
231 | |||
220 | static void clear_irq_range(struct pcie_port *pp, unsigned int irq_base, | 232 | static void clear_irq_range(struct pcie_port *pp, unsigned int irq_base, |
221 | unsigned int nvec, unsigned int pos) | 233 | unsigned int nvec, unsigned int pos) |
222 | { | 234 | { |
223 | unsigned int i, res, bit, val; | 235 | unsigned int i; |
224 | 236 | ||
225 | for (i = 0; i < nvec; i++) { | 237 | for (i = 0; i < nvec; i++) { |
226 | irq_set_msi_desc_off(irq_base, i, NULL); | 238 | irq_set_msi_desc_off(irq_base, i, NULL); |
227 | clear_bit(pos + i, pp->msi_irq_in_use); | 239 | clear_bit(pos + i, pp->msi_irq_in_use); |
228 | /* Disable corresponding interrupt on MSI controller */ | 240 | /* Disable corresponding interrupt on MSI controller */ |
229 | res = ((pos + i) / 32) * 12; | 241 | if (pp->ops->msi_clear_irq) |
230 | bit = (pos + i) % 32; | 242 | pp->ops->msi_clear_irq(pp, pos + i); |
231 | dw_pcie_rd_own_conf(pp, PCIE_MSI_INTR0_ENABLE + res, 4, &val); | 243 | else |
232 | val &= ~(1 << bit); | 244 | dw_pcie_msi_clear_irq(pp, pos + i); |
233 | dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE + res, 4, val); | ||
234 | } | 245 | } |
235 | } | 246 | } |
236 | 247 | ||
248 | static void dw_pcie_msi_set_irq(struct pcie_port *pp, int irq) | ||
249 | { | ||
250 | unsigned int res, bit, val; | ||
251 | |||
252 | res = (irq / 32) * 12; | ||
253 | bit = irq % 32; | ||
254 | dw_pcie_rd_own_conf(pp, PCIE_MSI_INTR0_ENABLE + res, 4, &val); | ||
255 | val |= 1 << bit; | ||
256 | dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE + res, 4, val); | ||
257 | } | ||
258 | |||
237 | static int assign_irq(int no_irqs, struct msi_desc *desc, int *pos) | 259 | static int assign_irq(int no_irqs, struct msi_desc *desc, int *pos) |
238 | { | 260 | { |
239 | int res, bit, irq, pos0, pos1, i; | 261 | int irq, pos0, pos1, i; |
240 | u32 val; | ||
241 | struct pcie_port *pp = sys_to_pcie(desc->dev->bus->sysdata); | 262 | struct pcie_port *pp = sys_to_pcie(desc->dev->bus->sysdata); |
242 | 263 | ||
243 | if (!pp) { | 264 | if (!pp) { |
@@ -281,11 +302,10 @@ static int assign_irq(int no_irqs, struct msi_desc *desc, int *pos) | |||
281 | } | 302 | } |
282 | set_bit(pos0 + i, pp->msi_irq_in_use); | 303 | set_bit(pos0 + i, pp->msi_irq_in_use); |
283 | /*Enable corresponding interrupt in MSI interrupt controller */ | 304 | /*Enable corresponding interrupt in MSI interrupt controller */ |
284 | res = ((pos0 + i) / 32) * 12; | 305 | if (pp->ops->msi_set_irq) |
285 | bit = (pos0 + i) % 32; | 306 | pp->ops->msi_set_irq(pp, pos0 + i); |
286 | dw_pcie_rd_own_conf(pp, PCIE_MSI_INTR0_ENABLE + res, 4, &val); | 307 | else |
287 | val |= 1 << bit; | 308 | dw_pcie_msi_set_irq(pp, pos0 + i); |
288 | dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE + res, 4, val); | ||
289 | } | 309 | } |
290 | 310 | ||
291 | *pos = pos0; | 311 | *pos = pos0; |
@@ -353,7 +373,10 @@ static int dw_msi_setup_irq(struct msi_chip *chip, struct pci_dev *pdev, | |||
353 | */ | 373 | */ |
354 | desc->msi_attrib.multiple = msgvec; | 374 | desc->msi_attrib.multiple = msgvec; |
355 | 375 | ||
356 | msg.address_lo = virt_to_phys((void *)pp->msi_data); | 376 | if (pp->ops->get_msi_data) |
377 | msg.address_lo = pp->ops->get_msi_data(pp); | ||
378 | else | ||
379 | msg.address_lo = virt_to_phys((void *)pp->msi_data); | ||
357 | msg.address_hi = 0x0; | 380 | msg.address_hi = 0x0; |
358 | msg.data = pos; | 381 | msg.data = pos; |
359 | write_msi_msg(irq, &msg); | 382 | write_msi_msg(irq, &msg); |
@@ -396,10 +419,35 @@ static const struct irq_domain_ops msi_domain_ops = { | |||
396 | int __init dw_pcie_host_init(struct pcie_port *pp) | 419 | int __init dw_pcie_host_init(struct pcie_port *pp) |
397 | { | 420 | { |
398 | struct device_node *np = pp->dev->of_node; | 421 | struct device_node *np = pp->dev->of_node; |
422 | struct platform_device *pdev = to_platform_device(pp->dev); | ||
399 | struct of_pci_range range; | 423 | struct of_pci_range range; |
400 | struct of_pci_range_parser parser; | 424 | struct of_pci_range_parser parser; |
401 | u32 val; | 425 | struct resource *cfg_res; |
402 | int i; | 426 | u32 val, na, ns; |
427 | const __be32 *addrp; | ||
428 | int i, index; | ||
429 | |||
430 | /* Find the address cell size and the number of cells in order to get | ||
431 | * the untranslated address. | ||
432 | */ | ||
433 | of_property_read_u32(np, "#address-cells", &na); | ||
434 | ns = of_n_size_cells(np); | ||
435 | |||
436 | cfg_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "config"); | ||
437 | if (cfg_res) { | ||
438 | pp->config.cfg0_size = resource_size(cfg_res)/2; | ||
439 | pp->config.cfg1_size = resource_size(cfg_res)/2; | ||
440 | pp->cfg0_base = cfg_res->start; | ||
441 | pp->cfg1_base = cfg_res->start + pp->config.cfg0_size; | ||
442 | |||
443 | /* Find the untranslated configuration space address */ | ||
444 | index = of_property_match_string(np, "reg-names", "config"); | ||
445 | addrp = of_get_address(np, index, false, false); | ||
446 | pp->cfg0_mod_base = of_read_number(addrp, ns); | ||
447 | pp->cfg1_mod_base = pp->cfg0_mod_base + pp->config.cfg0_size; | ||
448 | } else { | ||
449 | dev_err(pp->dev, "missing *config* reg space\n"); | ||
450 | } | ||
403 | 451 | ||
404 | if (of_pci_range_parser_init(&parser, np)) { | 452 | if (of_pci_range_parser_init(&parser, np)) { |
405 | dev_err(pp->dev, "missing ranges property\n"); | 453 | dev_err(pp->dev, "missing ranges property\n"); |
@@ -422,17 +470,33 @@ int __init dw_pcie_host_init(struct pcie_port *pp) | |||
422 | pp->config.io_size = resource_size(&pp->io); | 470 | pp->config.io_size = resource_size(&pp->io); |
423 | pp->config.io_bus_addr = range.pci_addr; | 471 | pp->config.io_bus_addr = range.pci_addr; |
424 | pp->io_base = range.cpu_addr; | 472 | pp->io_base = range.cpu_addr; |
473 | |||
474 | /* Find the untranslated IO space address */ | ||
475 | pp->io_mod_base = of_read_number(parser.range - | ||
476 | parser.np + na, ns); | ||
425 | } | 477 | } |
426 | if (restype == IORESOURCE_MEM) { | 478 | if (restype == IORESOURCE_MEM) { |
427 | of_pci_range_to_resource(&range, np, &pp->mem); | 479 | of_pci_range_to_resource(&range, np, &pp->mem); |
428 | pp->mem.name = "MEM"; | 480 | pp->mem.name = "MEM"; |
429 | pp->config.mem_size = resource_size(&pp->mem); | 481 | pp->config.mem_size = resource_size(&pp->mem); |
430 | pp->config.mem_bus_addr = range.pci_addr; | 482 | pp->config.mem_bus_addr = range.pci_addr; |
483 | |||
484 | /* Find the untranslated MEM space address */ | ||
485 | pp->mem_mod_base = of_read_number(parser.range - | ||
486 | parser.np + na, ns); | ||
431 | } | 487 | } |
432 | if (restype == 0) { | 488 | if (restype == 0) { |
433 | of_pci_range_to_resource(&range, np, &pp->cfg); | 489 | of_pci_range_to_resource(&range, np, &pp->cfg); |
434 | pp->config.cfg0_size = resource_size(&pp->cfg)/2; | 490 | pp->config.cfg0_size = resource_size(&pp->cfg)/2; |
435 | pp->config.cfg1_size = resource_size(&pp->cfg)/2; | 491 | pp->config.cfg1_size = resource_size(&pp->cfg)/2; |
492 | pp->cfg0_base = pp->cfg.start; | ||
493 | pp->cfg1_base = pp->cfg.start + pp->config.cfg0_size; | ||
494 | |||
495 | /* Find the untranslated configuration space address */ | ||
496 | pp->cfg0_mod_base = of_read_number(parser.range - | ||
497 | parser.np + na, ns); | ||
498 | pp->cfg1_mod_base = pp->cfg0_mod_base + | ||
499 | pp->config.cfg0_size; | ||
436 | } | 500 | } |
437 | } | 501 | } |
438 | 502 | ||
@@ -445,8 +509,6 @@ int __init dw_pcie_host_init(struct pcie_port *pp) | |||
445 | } | 509 | } |
446 | } | 510 | } |
447 | 511 | ||
448 | pp->cfg0_base = pp->cfg.start; | ||
449 | pp->cfg1_base = pp->cfg.start + pp->config.cfg0_size; | ||
450 | pp->mem_base = pp->mem.start; | 512 | pp->mem_base = pp->mem.start; |
451 | 513 | ||
452 | pp->va_cfg0_base = devm_ioremap(pp->dev, pp->cfg0_base, | 514 | pp->va_cfg0_base = devm_ioremap(pp->dev, pp->cfg0_base, |
@@ -509,9 +571,9 @@ static void dw_pcie_prog_viewport_cfg0(struct pcie_port *pp, u32 busdev) | |||
509 | /* Program viewport 0 : OUTBOUND : CFG0 */ | 571 | /* Program viewport 0 : OUTBOUND : CFG0 */ |
510 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0, | 572 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0, |
511 | PCIE_ATU_VIEWPORT); | 573 | PCIE_ATU_VIEWPORT); |
512 | dw_pcie_writel_rc(pp, pp->cfg0_base, PCIE_ATU_LOWER_BASE); | 574 | dw_pcie_writel_rc(pp, pp->cfg0_mod_base, PCIE_ATU_LOWER_BASE); |
513 | dw_pcie_writel_rc(pp, (pp->cfg0_base >> 32), PCIE_ATU_UPPER_BASE); | 575 | dw_pcie_writel_rc(pp, (pp->cfg0_mod_base >> 32), PCIE_ATU_UPPER_BASE); |
514 | dw_pcie_writel_rc(pp, pp->cfg0_base + pp->config.cfg0_size - 1, | 576 | dw_pcie_writel_rc(pp, pp->cfg0_mod_base + pp->config.cfg0_size - 1, |
515 | PCIE_ATU_LIMIT); | 577 | PCIE_ATU_LIMIT); |
516 | dw_pcie_writel_rc(pp, busdev, PCIE_ATU_LOWER_TARGET); | 578 | dw_pcie_writel_rc(pp, busdev, PCIE_ATU_LOWER_TARGET); |
517 | dw_pcie_writel_rc(pp, 0, PCIE_ATU_UPPER_TARGET); | 579 | dw_pcie_writel_rc(pp, 0, PCIE_ATU_UPPER_TARGET); |
@@ -525,9 +587,9 @@ static void dw_pcie_prog_viewport_cfg1(struct pcie_port *pp, u32 busdev) | |||
525 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1, | 587 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1, |
526 | PCIE_ATU_VIEWPORT); | 588 | PCIE_ATU_VIEWPORT); |
527 | dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_CFG1, PCIE_ATU_CR1); | 589 | dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_CFG1, PCIE_ATU_CR1); |
528 | dw_pcie_writel_rc(pp, pp->cfg1_base, PCIE_ATU_LOWER_BASE); | 590 | dw_pcie_writel_rc(pp, pp->cfg1_mod_base, PCIE_ATU_LOWER_BASE); |
529 | dw_pcie_writel_rc(pp, (pp->cfg1_base >> 32), PCIE_ATU_UPPER_BASE); | 591 | dw_pcie_writel_rc(pp, (pp->cfg1_mod_base >> 32), PCIE_ATU_UPPER_BASE); |
530 | dw_pcie_writel_rc(pp, pp->cfg1_base + pp->config.cfg1_size - 1, | 592 | dw_pcie_writel_rc(pp, pp->cfg1_mod_base + pp->config.cfg1_size - 1, |
531 | PCIE_ATU_LIMIT); | 593 | PCIE_ATU_LIMIT); |
532 | dw_pcie_writel_rc(pp, busdev, PCIE_ATU_LOWER_TARGET); | 594 | dw_pcie_writel_rc(pp, busdev, PCIE_ATU_LOWER_TARGET); |
533 | dw_pcie_writel_rc(pp, 0, PCIE_ATU_UPPER_TARGET); | 595 | dw_pcie_writel_rc(pp, 0, PCIE_ATU_UPPER_TARGET); |
@@ -540,9 +602,9 @@ static void dw_pcie_prog_viewport_mem_outbound(struct pcie_port *pp) | |||
540 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0, | 602 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0, |
541 | PCIE_ATU_VIEWPORT); | 603 | PCIE_ATU_VIEWPORT); |
542 | dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_MEM, PCIE_ATU_CR1); | 604 | dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_MEM, PCIE_ATU_CR1); |
543 | dw_pcie_writel_rc(pp, pp->mem_base, PCIE_ATU_LOWER_BASE); | 605 | dw_pcie_writel_rc(pp, pp->mem_mod_base, PCIE_ATU_LOWER_BASE); |
544 | dw_pcie_writel_rc(pp, (pp->mem_base >> 32), PCIE_ATU_UPPER_BASE); | 606 | dw_pcie_writel_rc(pp, (pp->mem_mod_base >> 32), PCIE_ATU_UPPER_BASE); |
545 | dw_pcie_writel_rc(pp, pp->mem_base + pp->config.mem_size - 1, | 607 | dw_pcie_writel_rc(pp, pp->mem_mod_base + pp->config.mem_size - 1, |
546 | PCIE_ATU_LIMIT); | 608 | PCIE_ATU_LIMIT); |
547 | dw_pcie_writel_rc(pp, pp->config.mem_bus_addr, PCIE_ATU_LOWER_TARGET); | 609 | dw_pcie_writel_rc(pp, pp->config.mem_bus_addr, PCIE_ATU_LOWER_TARGET); |
548 | dw_pcie_writel_rc(pp, upper_32_bits(pp->config.mem_bus_addr), | 610 | dw_pcie_writel_rc(pp, upper_32_bits(pp->config.mem_bus_addr), |
@@ -556,9 +618,9 @@ static void dw_pcie_prog_viewport_io_outbound(struct pcie_port *pp) | |||
556 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1, | 618 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1, |
557 | PCIE_ATU_VIEWPORT); | 619 | PCIE_ATU_VIEWPORT); |
558 | dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_IO, PCIE_ATU_CR1); | 620 | dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_IO, PCIE_ATU_CR1); |
559 | dw_pcie_writel_rc(pp, pp->io_base, PCIE_ATU_LOWER_BASE); | 621 | dw_pcie_writel_rc(pp, pp->io_mod_base, PCIE_ATU_LOWER_BASE); |
560 | dw_pcie_writel_rc(pp, (pp->io_base >> 32), PCIE_ATU_UPPER_BASE); | 622 | dw_pcie_writel_rc(pp, (pp->io_mod_base >> 32), PCIE_ATU_UPPER_BASE); |
561 | dw_pcie_writel_rc(pp, pp->io_base + pp->config.io_size - 1, | 623 | dw_pcie_writel_rc(pp, pp->io_mod_base + pp->config.io_size - 1, |
562 | PCIE_ATU_LIMIT); | 624 | PCIE_ATU_LIMIT); |
563 | dw_pcie_writel_rc(pp, pp->config.io_bus_addr, PCIE_ATU_LOWER_TARGET); | 625 | dw_pcie_writel_rc(pp, pp->config.io_bus_addr, PCIE_ATU_LOWER_TARGET); |
564 | dw_pcie_writel_rc(pp, upper_32_bits(pp->config.io_bus_addr), | 626 | dw_pcie_writel_rc(pp, upper_32_bits(pp->config.io_bus_addr), |
@@ -656,7 +718,11 @@ static int dw_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where, | |||
656 | } | 718 | } |
657 | 719 | ||
658 | if (bus->number != pp->root_bus_nr) | 720 | if (bus->number != pp->root_bus_nr) |
659 | ret = dw_pcie_rd_other_conf(pp, bus, devfn, | 721 | if (pp->ops->rd_other_conf) |
722 | ret = pp->ops->rd_other_conf(pp, bus, devfn, | ||
723 | where, size, val); | ||
724 | else | ||
725 | ret = dw_pcie_rd_other_conf(pp, bus, devfn, | ||
660 | where, size, val); | 726 | where, size, val); |
661 | else | 727 | else |
662 | ret = dw_pcie_rd_own_conf(pp, where, size, val); | 728 | ret = dw_pcie_rd_own_conf(pp, where, size, val); |
@@ -679,7 +745,11 @@ static int dw_pcie_wr_conf(struct pci_bus *bus, u32 devfn, | |||
679 | return PCIBIOS_DEVICE_NOT_FOUND; | 745 | return PCIBIOS_DEVICE_NOT_FOUND; |
680 | 746 | ||
681 | if (bus->number != pp->root_bus_nr) | 747 | if (bus->number != pp->root_bus_nr) |
682 | ret = dw_pcie_wr_other_conf(pp, bus, devfn, | 748 | if (pp->ops->wr_other_conf) |
749 | ret = pp->ops->wr_other_conf(pp, bus, devfn, | ||
750 | where, size, val); | ||
751 | else | ||
752 | ret = dw_pcie_wr_other_conf(pp, bus, devfn, | ||
683 | where, size, val); | 753 | where, size, val); |
684 | else | 754 | else |
685 | ret = dw_pcie_wr_own_conf(pp, where, size, val); | 755 | ret = dw_pcie_wr_own_conf(pp, where, size, val); |